Skip to content

Commit 6ab469f

Browse files
committed
version: replace nerdbank with version file
Remove Nerdbank.GitVersioning dependency from project in favor of a new VERSION file, which will be updated ahead of each release. Versioning in this file will begin with the version we plan to use for the next release: 2.1.0.0. This change involves the addition of a new custom MSBuild task, which reads in the contents of the VERSION file, converts it to a Version object, and then sets the various version-related MSBuild properties with the correct value (some with the `Revision` component appended, others without). Note that there is a bug in MSAL [1] that causes build failures for projects without dependencies with this change. We add Newtonsoft.Json as a global dependency in Directory.Build.props to work around this problem until the fix is released. [1]: AzureAD/microsoft-authentication-library-for-dotnet#4108
1 parent f1a235d commit 6ab469f

File tree

9 files changed

+71
-24
lines changed

9 files changed

+71
-24
lines changed

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<!-- All projects should use Nerdbank.GitVersioning for consistent version numbers -->
31-
<PackageReference Include="Nerdbank.GitVersioning">
32-
<Version>3.4.244</Version>
33-
<PrivateAssets>all</PrivateAssets>
30+
<!-- Workaround https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4108 -->
31+
<PackageReference Include="Newtonsoft.Json">
32+
<Version>13.0.1</Version>
3433
</PackageReference>
3534
</ItemGroup>
35+
3636
</Project>

Directory.Build.targets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
<!-- Load custom build tasks -->
66
<Import Project="$(RepoPath)build\GCM.tasks" />
77

8+
<!-- Use version specified in VERSION file -->
9+
<Target Name="GetVersion" BeforeTargets="BeforeBuild">
10+
<GetVersion VersionFile="$(RepoPath)VERSION">
11+
<Output TaskParameter="Version" PropertyName="Version" />
12+
<Output TaskParameter="AssemblyVersion" PropertyName="AssemblyVersion" />
13+
<Output TaskParameter="FileVersion" PropertyName="FileVersion" />
14+
</GetVersion>
15+
</Target>
16+
817
<!-- Windows application manifest generation -->
918
<PropertyGroup Condition="'$(GenerateWindowsAppManifest)' != 'false'">
1019
<ApplicationManifest>$(IntermediateOutputPath)app.manifest</ApplicationManifest>

VERSION

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

build/GCM.tasks

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
<Code Type="Class" Source="$(MSBuildThisFileDirectory)GenerateWindowsAppManifest.cs" />
1414
</Task>
1515
</UsingTask>
16+
17+
<UsingTask TaskName="GetVersion" TaskFactory="$(_TaskFactory)" AssemblyFile="$(_TaskAssembly)">
18+
<Task>
19+
<Code Type="Class" Source="$(MSBuildThisFileDirectory)GetVersion.cs" />
20+
</Task>
21+
</UsingTask>
1622
</Project>

build/GetVersion.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Microsoft.Build.Framework;
2+
using Microsoft.Build.Utilities;
3+
using System.IO;
4+
5+
namespace GitCredentialManager.MSBuild
6+
{
7+
public class GetVersion : Task
8+
{
9+
[Required]
10+
public string VersionFile { get; set; }
11+
12+
[Output]
13+
public string Version { get; set; }
14+
15+
[Output]
16+
public string AssemblyVersion { get; set; }
17+
18+
[Output]
19+
public string FileVersion { get; set; }
20+
21+
public override bool Execute()
22+
{
23+
Log.LogMessage(MessageImportance.Normal, "Reading VERSION file...");
24+
string textVersion = File.ReadAllText(VersionFile);
25+
26+
if (!System.Version.TryParse(textVersion, out System.Version fullVersion))
27+
{
28+
Log.LogError("Invalid version '{0}' specified.", textVersion);
29+
return false;
30+
}
31+
32+
// System.Version names its version components as follows:
33+
// major.minor[.build[.revision]]
34+
// The main version number we use for GCM contains the first three
35+
// components.
36+
// The assembly and file version numbers contain all components, as
37+
// ommitting the revision portion from these properties causes
38+
// runtime failures on Windows.
39+
Version = $"{fullVersion.Major}.{fullVersion.Minor}.{fullVersion.Build}";
40+
AssemblyVersion = FileVersion = fullVersion.ToString();
41+
42+
return true;
43+
}
44+
}
45+
}

src/linux/Packaging.Linux/Packaging.Linux.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
<!-- Implicit SDK targets import (so we can override the default targets below) -->
2323
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
2424

25-
<Target Name="CoreCompile" DependsOnTargets="GetBuildVersion" Condition="'$(OSPlatform)'=='linux'">
26-
<Message Text="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(BuildVersionSimple)'" Importance="High" />
27-
<Exec Command="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(BuildVersionSimple)'" />
25+
<Target Name="CoreCompile" Condition="'$(OSPlatform)'=='linux'">
26+
<Message Text="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(Version)'" Importance="High" />
27+
<Exec Command="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(Version)'" />
2828
</Target>
2929

3030
<Target Name="CoreClean">

src/osx/Installer.Mac/Installer.Mac.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
<!-- Implicit SDK targets import (so we can override the default targets below) -->
1919
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
2020

21-
<Target Name="CoreCompile" DependsOnTargets="GetBuildVersion" Condition="'$(OSPlatform)'=='osx'">
22-
<Message Text="$(MSBuildProjectDirectory)\build.sh --configuration='$(Configuration)' --version='$(BuildVersionSimple)' --runtime='$(RuntimeIdentifier)'" Importance="High" />
23-
<Exec Command="$(MSBuildProjectDirectory)\build.sh --configuration='$(Configuration)' --version='$(BuildVersionSimple)' --runtime='$(RuntimeIdentifier)'" />
21+
<Target Name="CoreCompile" Condition="'$(OSPlatform)'=='osx'">
22+
<Message Text="$(MSBuildProjectDirectory)\build.sh --configuration='$(Configuration)' --version='$(Version)' --runtime='$(RuntimeIdentifier)'" Importance="High" />
23+
<Exec Command="$(MSBuildProjectDirectory)\build.sh --configuration='$(Configuration)' --version='$(Version)' --runtime='$(RuntimeIdentifier)'" />
2424
</Target>
2525

2626
<Target Name="CoreClean">

src/shared/Core/Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2625
<PackageReference Include="Microsoft.Identity.Client" Version="4.52.0" />
2726
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.28.0" />
2827
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21216.1" />

version.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)