Skip to content
Permalink
Browse files

[Build] Adjust package versioning so that NuGetVersion doesn't contai…

…n build metadata
  • Loading branch information
xen2 committed Dec 8, 2018
1 parent 9db1b34 commit 4bd757dffbf8b128b33366f5270e2912853e9a58
@@ -103,7 +103,7 @@ Example of use:
<MSBuild Targets="Build" Projects="$(XenkoRoot)deps\Xenko.GitVersioning\Xenko.GitVersioning.csproj"/>

<!-- Create SharedAssemblyInfo.NuGet.cs with Git information (different between official build and internal builds) -->
<GenerateVersionFile Condition="'$(XenkoOfficialBuild)' == 'true'" RootDirectory="$(XenkoRoot)" VersionFile="sources\shared\SharedAssemblyInfo.cs" GeneratedVersionFile="sources\shared\SharedAssemblyInfo.NuGet.cs">
<GenerateVersionFile Condition="'$(XenkoOfficialBuild)' == 'true'" RootDirectory="$(XenkoRoot)" VersionFile="sources\shared\SharedAssemblyInfo.cs" GeneratedVersionFile="sources\shared\SharedAssemblyInfo.NuGet.cs" SpecialVersionGitCommit="true">
<Output TaskParameter="NuGetVersion" PropertyName="XenkoPackageVersion"/>
</GenerateVersionFile>
<GenerateVersionFile Condition="'$(XenkoOfficialBuild)' != 'true'" RootDirectory="$(XenkoRoot)" VersionFile="sources\shared\SharedAssemblyInfo.cs" GeneratedVersionFile="sources\shared\SharedAssemblyInfo.NuGet.cs" SpecialVersion="beta" SpecialVersionGitHeight="true" SpecialVersionGitCommit="true">
@@ -96,10 +96,6 @@ public override bool Execute()
var height = Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(repo, VersionFile.ItemSpec);
versionSuffix += height.ToString("D5");
}
if (SpecialVersionGitCommit && headCommitSha != null)
{
versionSuffix += "+g" + headCommitSha.Substring(0, 8);
}

// Prefix with dash (if non empty)
if (versionSuffix.Length > 0 && !versionSuffix.StartsWith("+"))
@@ -108,17 +104,13 @@ public override bool Execute()
// Replace NuGetVersionSuffix
versionFileData = Regex.Replace(versionFileData, "NuGetVersionSuffix = (.*);", $"NuGetVersionSuffix = \"{versionSuffix}\";");

var assemblyInformationalSuffix = "NuGetVersionSuffix";

// Always include git commit (even if not part of NuGetVersionSuffix)
if (!SpecialVersionGitCommit && headCommitSha != null)
if (SpecialVersionGitCommit && headCommitSha != null)
{
assemblyInformationalSuffix += $" + \"-g{headCommitSha.Substring(0, 8)}\"";
// Replace build metadata
versionFileData = Regex.Replace(versionFileData, "BuildMetadata = (.*);", $"BuildMetadata = \"+g{headCommitSha.Substring(0, 8)}\";");
}

// Replace AssemblyInformationalSuffix
versionFileData = Regex.Replace(versionFileData, "AssemblyInformationalSuffix = (.*);", $"AssemblyInformationalSuffix = {assemblyInformationalSuffix};");

// Write back new file
File.WriteAllText(Path.Combine(RootDirectory.ItemSpec, GeneratedVersionFile.ItemSpec), versionFileData);

@@ -48,14 +48,14 @@ internal class XenkoVersion
public const string NuGetVersionSuffix = "-dev";

/// <summary>
/// The informational assembly version, containing -dev or -g[git_hash] during package.
/// The build metadata, usually +g[git_hash] during package. Note: might be replaced during package build.
/// </summary>
public const string AssemblyInformationalVersion = PublicVersion + AssemblyInformationalSuffix;
public const string BuildMetadata = "";

/// <summary>
/// The assembly suffix. Note: replaced by git commit during package build.
/// The informational assembly version, containing -dev or +g[git_hash] during package.
/// </summary>
private const string AssemblyInformationalSuffix = "-dev";
public const string AssemblyInformationalVersion = PublicVersion + NuGetVersionSuffix + BuildMetadata;
}

/// <summary>
@@ -11,7 +11,9 @@
<_XenkoSharedAssemblyInfoLines Condition="'$(XenkoPackageBuild)' == 'true'">$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)..\shared\SharedAssemblyInfo.NuGet.cs'))</_XenkoSharedAssemblyInfoLines>
<_XenkoSharedAssemblyInfoLines Condition="'$(XenkoPackageBuild)' != 'true'">$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)..\shared\SharedAssemblyInfo.cs'))</_XenkoSharedAssemblyInfoLines>
<XenkoPublicVersion>$([System.Text.RegularExpressions.Regex]::Match($(_XenkoSharedAssemblyInfoLines), `.*PublicVersion = \"(.*)\";.*`).Groups[1].Value)</XenkoPublicVersion>
<XenkoNuGetVersion>$(XenkoPublicVersion)$([System.Text.RegularExpressions.Regex]::Match($(_XenkoSharedAssemblyInfoLines), `.*NuGetVersionSuffix = \"(.*)\";.*`).Groups[1].Value)</XenkoNuGetVersion>
<XenkoNuGetVersionSuffix>$([System.Text.RegularExpressions.Regex]::Match($(_XenkoSharedAssemblyInfoLines), `.*NuGetVersionSuffix = \"(.*)\";.*`).Groups[1].Value)</XenkoNuGetVersionSuffix>
<XenkoBuildMetadata>$([System.Text.RegularExpressions.Regex]::Match($(_XenkoSharedAssemblyInfoLines), `.*BuildMetadata = \"(.*)\";.*`).Groups[1].Value)</XenkoBuildMetadata>
<XenkoNuGetVersion>$(XenkoPublicVersion)$(XenkoNuGetVersionSuffix)$(XenkoBuildMetadata)</XenkoNuGetVersion>

<PackageVersion Condition=" '$(PackageVersion)' == '' ">$(XenkoNuGetVersion)</PackageVersion>
<PackageLicenseUrl>https://github.com/xenko3d/xenko/blob/master/LICENSE.md</PackageLicenseUrl>

0 comments on commit 4bd757d

Please sign in to comment.
You can’t perform that action at this time.