Skip to content

Commit

Permalink
version: replace nerdbank with version file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ldennington committed Apr 29, 2023
1 parent f1a235d commit 6ab469f
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 24 deletions.
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
</PropertyGroup>

<ItemGroup>
<!-- All projects should use Nerdbank.GitVersioning for consistent version numbers -->
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.4.244</Version>
<PrivateAssets>all</PrivateAssets>
<!-- Workaround https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4108 -->
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<!-- Load custom build tasks -->
<Import Project="$(RepoPath)build\GCM.tasks" />

<!-- Use version specified in VERSION file -->
<Target Name="GetVersion" BeforeTargets="BeforeBuild">
<GetVersion VersionFile="$(RepoPath)VERSION">
<Output TaskParameter="Version" PropertyName="Version" />
<Output TaskParameter="AssemblyVersion" PropertyName="AssemblyVersion" />
<Output TaskParameter="FileVersion" PropertyName="FileVersion" />
</GetVersion>
</Target>

<!-- Windows application manifest generation -->
<PropertyGroup Condition="'$(GenerateWindowsAppManifest)' != 'false'">
<ApplicationManifest>$(IntermediateOutputPath)app.manifest</ApplicationManifest>
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1.0.0
6 changes: 6 additions & 0 deletions build/GCM.tasks
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
<Code Type="Class" Source="$(MSBuildThisFileDirectory)GenerateWindowsAppManifest.cs" />
</Task>
</UsingTask>

<UsingTask TaskName="GetVersion" TaskFactory="$(_TaskFactory)" AssemblyFile="$(_TaskAssembly)">
<Task>
<Code Type="Class" Source="$(MSBuildThisFileDirectory)GetVersion.cs" />
</Task>
</UsingTask>
</Project>
45 changes: 45 additions & 0 deletions build/GetVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.IO;

namespace GitCredentialManager.MSBuild
{
public class GetVersion : Task
{
[Required]
public string VersionFile { get; set; }

[Output]
public string Version { get; set; }

[Output]
public string AssemblyVersion { get; set; }

[Output]
public string FileVersion { get; set; }

public override bool Execute()
{
Log.LogMessage(MessageImportance.Normal, "Reading VERSION file...");
string textVersion = File.ReadAllText(VersionFile);

if (!System.Version.TryParse(textVersion, out System.Version fullVersion))
{
Log.LogError("Invalid version '{0}' specified.", textVersion);
return false;
}

// System.Version names its version components as follows:
// major.minor[.build[.revision]]
// The main version number we use for GCM contains the first three
// components.
// The assembly and file version numbers contain all components, as
// ommitting the revision portion from these properties causes
// runtime failures on Windows.
Version = $"{fullVersion.Major}.{fullVersion.Minor}.{fullVersion.Build}";
AssemblyVersion = FileVersion = fullVersion.ToString();

return true;
}
}
}
6 changes: 3 additions & 3 deletions src/linux/Packaging.Linux/Packaging.Linux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<!-- Implicit SDK targets import (so we can override the default targets below) -->
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

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

<Target Name="CoreClean">
Expand Down
6 changes: 3 additions & 3 deletions src/osx/Installer.Mac/Installer.Mac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<!-- Implicit SDK targets import (so we can override the default targets below) -->
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

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

<Target Name="CoreClean">
Expand Down
1 change: 0 additions & 1 deletion src/shared/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.52.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.28.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21216.1" />
Expand Down
13 changes: 0 additions & 13 deletions version.json

This file was deleted.

0 comments on commit 6ab469f

Please sign in to comment.