Skip to content

Commit d16b1e5

Browse files
authored
[build] Use GitInfo to generate $(Version) (#865)
[build] Use GitInfo to generate $(Version) (#865) Context: http://github.com/xamarin/xamarin-android/commit/2d81740cc1c708cd0474c9eac8936cd7abfc72e3 Context: dotnet/android#5749 In order to better support building solutions which reference both .NET 6 and legacy projects within Visual Studio, we have begun strong-naming all the MSBuild-related assemblies; see also ff27142. This allows loading two different version of the "same" assembly, e.g. `Java.Interop.Tools.Diagnostics.dll`, from two different filesystem locations in the same AppDomain/AssemblyLoadContext. However, strong-naming is only part of the solution. The other part is that, for sanity and reliability, the "two different versions of the 'same' assembly" should *also* have different assembly *versions*. If they have the same assembly version, are they truly different? Update the build system by adding a `Directory.Build.targets` and `GitInfo.txt` file so that the the [`GitInfo`][0] [NuGet Package][1] will be used to "fully" set the `$(Version)` MSBuild property, consisting of the major and minor version numbers contained within `GitInfo.txt`, along with a "computed" `$(GitSemVerPatch)` value based on the "patch version" in `GitInfo.txt`, if present, added to the number of commits which have occurred since `GitInfo.txt` changed. Additionally, set the `$(InformationalVersion)` MSBuild property so that it mirrors the behavior in [`Mono.Android.dll`][2]: [assembly: System.Reflection.AssemblyInformationalVersionAttribute("0.1.1; git-rev-head:2eb9ff2; git-branch:main") Setting the `$(Version)` and `$(InformationalVersion)` MSBuild properties also requires setting `$(GenerateAssemblyInfo)`=True. Update `src/Java.Interop/Properties/AssemblyInfo.cs` to remove the attributes that `$(GenerateAssemblyInfo)` will generate. Other: * Centralize the `$(Company)` and `$(Copyright)` values. * Various whitespace changes due to `.editorconfig`. [0]: https://github.com/devlooped/GitInfo [1]: https://www.nuget.org/packages/GitInfo/2.1.2 [2]: dotnet/android@b620689
1 parent 2eb9ff2 commit d16b1e5

File tree

11 files changed

+34
-32
lines changed

11 files changed

+34
-32
lines changed

Directory.Build.props

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<_OutputPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\</_OutputPath>
7+
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
78
</PropertyGroup>
8-
9+
910
<PropertyGroup>
1011
<XlfLanguages>cs;de;es;fr;it;ja;ko;pl;pt-BR;ru;tr;zh-Hans;zh-Hant</XlfLanguages>
1112
<UpdateXlfOnBuild Condition="'$(RunningOnCI)' != 'true'">true</UpdateXlfOnBuild>
@@ -75,7 +76,7 @@
7576
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">$(DotnetToolPath) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
7677
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
7778
</PropertyGroup>
78-
79+
7980
<!-- Add Roslyn analyzers NuGet to all projects -->
8081
<ItemGroup Condition=" '$(DisableRoslynAnalyzers)' != 'True' ">
8182
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
@@ -84,4 +85,21 @@
8485
</PackageReference>
8586
</ItemGroup>
8687

88+
<!-- GitInfo Package for Assembly Versioning -->
89+
<ItemGroup>
90+
<PackageReference Include="GitInfo" Version="2.1.2" PrivateAssets="all" />
91+
</ItemGroup>
92+
<PropertyGroup>
93+
<GitDefaultBranch>main</GitDefaultBranch>
94+
<GitThisAssembly>false</GitThisAssembly>
95+
</PropertyGroup>
96+
97+
<Target Name="SetVersion" BeforeTargets="GetAssemblyVersion;GetPackageVersion" DependsOnTargets="GitVersion">
98+
<PropertyGroup>
99+
<Version>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)</Version>
100+
<InformationalVersion>$(Version); git-rev-head:$(GitCommit); git-branch:$(GitBranch)</InformationalVersion>
101+
<Company>Microsoft Corporation</Company>
102+
<Copyright>Microsoft Corporation</Copyright>
103+
</PropertyGroup>
104+
</Target>
87105
</Project>

GitInfo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1

build-tools/automation/azure-pipelines.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
solution: Java.Interop.sln
5959
configuration: $(Build.Configuration)
6060
msbuildArguments: /restore
61-
61+
6262
- task: MSBuild@1
6363
displayName: MSBuild RunNUnitTests.targets
6464
inputs:
@@ -93,7 +93,7 @@ jobs:
9393
runNativeDotnetTests: true
9494

9595
- template: templates\fail-on-issue.yaml
96-
96+
9797
- job: mac_build
9898
displayName: Mac - Mono
9999
pool:
@@ -114,10 +114,10 @@ jobs:
114114
115115
- script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
116116
displayName: make prepare
117-
117+
118118
- script: make all CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
119119
displayName: make all
120-
120+
121121
- script: |
122122
r=0
123123
make run-all-tests CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) || r=$?
@@ -139,7 +139,7 @@ jobs:
139139
SourceFolder: $(System.DefaultWorkingDirectory)
140140
Contents: |
141141
xatb.jar
142-
bin.zip
142+
bin.zip
143143
TargetFolder: $(Build.ArtifactStagingDirectory)
144144
condition: succeededOrFailed()
145145

@@ -148,7 +148,7 @@ jobs:
148148
inputs:
149149
ArtifactName: debug
150150
condition: succeededOrFailed()
151-
151+
152152
- job: mac_dotnet_build
153153
displayName: Mac - .NET Core
154154
pool:
@@ -161,12 +161,12 @@ jobs:
161161
submodules: recursive
162162

163163
- template: templates\install-dependencies.yaml
164-
164+
165165
- script: make prepare-core CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
166166
displayName: make prepare-core
167-
167+
168168
- template: templates\core-build.yaml
169-
169+
170170
- template: templates\core-tests.yaml
171171
parameters:
172172
runNativeTests: true

src/Java.Interop.Dynamic/Java.Interop.Dynamic.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<SignAssembly>true</SignAssembly>
88
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
99
<AssemblyTitle>Java.Interop.Dynamic</AssemblyTitle>
10-
<Company>Microsoft Corporation</Company>
11-
<Copyright>Microsoft Corporation</Copyright>
12-
<AssemblyVersion>0.1.0.0</AssemblyVersion>
1310
</PropertyGroup>
1411
<PropertyGroup>
1512
<OutputPath>$(ToolOutputFullPath)</OutputPath>

src/Java.Interop.Export/Java.Interop.Export.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<SignAssembly>true</SignAssembly>
88
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
99
<AssemblyTitle>Java.Interop.Export</AssemblyTitle>
10-
<Company>Microsoft Corporation</Company>
11-
<Copyright>Microsoft Corporation</Copyright>
12-
<AssemblyVersion>0.1.0.0</AssemblyVersion>
1310
</PropertyGroup>
1411
<PropertyGroup>
1512
<OutputPath>$(ToolOutputFullPath)</OutputPath>

src/Java.Interop.GenericMarshaler/Java.Interop.GenericMarshaler.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<SignAssembly>true</SignAssembly>
88
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
99
<AssemblyTitle>Java.Interop.GenericMarshaler</AssemblyTitle>
10-
<Company>Microsoft Corporation</Company>
11-
<Copyright>Microsoft Corporation</Copyright>
12-
<AssemblyVersion>0.1.0.0</AssemblyVersion>
1310
</PropertyGroup>
1411
<PropertyGroup>
1512
<OutputPath>$(ToolOutputFullPath)</OutputPath>

src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<DefineConstants>INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
88
<ProjectGuid>{5C0B3562-8DA0-4726-9762-75B9709ED6B7}</ProjectGuid>
99
<AssemblyTitle>Java.Interop.Tools.JavaSource</AssemblyTitle>
10-
<Company>Microsoft Corporation</Company>
11-
<Copyright>Microsoft Corporation</Copyright>
12-
<AssemblyVersion>0.1.0.0</AssemblyVersion>
1310
</PropertyGroup>
1411
<PropertyGroup>
1512
<OutputPath>$(ToolOutputFullPath)</OutputPath>

src/Java.Interop/Java.Interop.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
2323
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES;$(JavaInteropDefineConstants)</DefineConstants>
2424
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
25-
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
2625
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\</IntermediateOutputPath>
2726
<OutputPath>$(ToolOutputFullPath)</OutputPath>
2827
<DocumentationFile>$(ToolOutputFullPath)Java.Interop.xml</DocumentationFile>

src/Java.Interop/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@
44

55
[assembly: DefaultDllImportSearchPathsAttribute (DllImportSearchPath.SafeDirectories | DllImportSearchPath.AssemblyDirectory)]
66

7-
[assembly: AssemblyTitle ("Java.Interop")]
87
[assembly: AssemblyDescription ("")]
98
[assembly: AssemblyCulture ("")]
10-
[assembly: AssemblyConfiguration ("")]
11-
[assembly: AssemblyCompany ("Microsoft Corporation")]
12-
[assembly: AssemblyCopyright ("Microsoft Corporation")]
13-
[assembly: AssemblyProduct ("")]
14-
[assembly: AssemblyTrademark ("Microsoft Corporation")]
15-
[assembly: AssemblyVersion ("0.1.0.0")]
9+
1610
[assembly: AssemblyMetadata ("IsTrimmable", "True")]
1711

1812
[assembly: InternalsVisibleTo (

tests/Java.Interop-Tests/Java.Interop-Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
<SignAssembly>true</SignAssembly>
8+
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
79
</PropertyGroup>
810

911
<PropertyGroup>

0 commit comments

Comments
 (0)