Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Adopt new versioning strategy
Browse files Browse the repository at this point in the history
Adopt new package and DLL versioning strategy,  See #3.  Nuget packages will be full semver-numbered.  AssemblyFileVersion and AssemblyInformationVersion attributes will be full semver-numbered.  AssemblyVersion attribute will by Major.0.0.0 numbered.
  • Loading branch information
reisenberger committed May 3, 2018
1 parent ef951e9 commit 0e01b70
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 35 deletions.
96 changes: 62 additions & 34 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ var projectToNugetFolderMap = new Dictionary<string, string[]>() {
var gitVersionPath = ToolsExePath("GitVersion.exe");
Dictionary<string, object> gitVersionOutput;

// Versioning
string nugetVersion;
string appveyorBuildNumber;
string assemblyVersion;
string assemblySemver;

// StrongNameSigner
var strongNameSignerPath = ToolsExePath("StrongNameSigner.Console.exe");

Expand Down Expand Up @@ -125,37 +131,62 @@ Task("__UpdateAssemblyVersionInformation")
gitVersionOutput = new JsonParser().Parse<Dictionary<string, object>>(output);

Information("Updated GlobalAssemblyInfo");
Information("AssemblyVersion -> {0}", gitVersionOutput["AssemblySemVer"]);
Information("AssemblyFileVersion -> {0}", gitVersionOutput["MajorMinorPatch"]);
Information("AssemblyInformationalVersion -> {0}", gitVersionOutput["InformationalVersion"]);

Information("");
Information("Obtained raw version info for package versioning:");
Information("NuGetVersion -> {0}", gitVersionOutput["NuGetVersion"]);
Information("FullSemVer -> {0}", gitVersionOutput["FullSemVer"]);
Information("AssemblySemVer -> {0}", gitVersionOutput["AssemblySemVer"]);

appveyorBuildNumber = gitVersionOutput["FullSemVer"].ToString();
nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
assemblyVersion = gitVersionOutput["Major"].ToString() + ".0.0.0";
assemblySemver = gitVersionOutput["AssemblySemVer"].ToString();

Information("");
Information("Mapping versioning information to:");
Information("Appveyor build number -> {0}", appveyorBuildNumber);
Information("Nuget package version -> {0}", nugetVersion);
Information("AssemblyVersion -> {0}", assemblyVersion);
Information("AssemblyFileVersion -> {0}", assemblySemver);
Information("AssemblyInformationalVersion -> {0}", assemblySemver);
});

Task("__UpdateDotNetStandardAssemblyVersionNumber")
.Does(() =>
{
// NOTE: TEMPORARY fix only, while GitVersionTask does not support .Net Standard assemblies. See https://github.com/App-vNext/Polly/issues/176.
// This build Task can be removed when GitVersionTask supports .Net Standard assemblies.
var assemblySemVer = gitVersionOutput["AssemblySemVer"].ToString();
Information("Updating NetStandard AssemblyVersions to {0}", assemblySemVer);
Information("Updating Assembly Version Information");

var attributeToValueMap = new Dictionary<string, string>() {
{ "AssemblyVersion", assemblyVersion },
{ "AssemblyFileVersion", assemblySemver },
{ "AssemblyInformationalVersion", assemblySemver },
};

var assemblyInfosToUpdate = GetFiles("./src/**/Properties/AssemblyInfo.cs")
.Select(f => f.FullPath)
.Where(f => !f.Contains("Specs"));

foreach(var assemblyInfo in assemblyInfosToUpdate) {
var replacedFiles = ReplaceRegexInFiles(assemblyInfo, "AssemblyVersion[(]\".*\"[)]", "AssemblyVersion(\"" + assemblySemVer +"\")");
if (!replacedFiles.Any())
{
throw new Exception($"AssemblyVersion could not be updated in {assemblyInfo}.");
foreach(var attributeMap in attributeToValueMap) {
var attribute = attributeMap.Key;
var value = attributeMap.Value;

foreach(var assemblyInfo in assemblyInfosToUpdate) {
var replacedFiles = ReplaceRegexInFiles(assemblyInfo, attribute + "[(]\".*\"[)]", attribute + "(\"" + value +"\")");
if (!replacedFiles.Any())
{
throw new Exception($"{attribute} attribute could not be updated in {assemblyInfo}.");
}
}
}

});

Task("__UpdateAppVeyorBuildNumber")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
var fullSemVer = gitVersionOutput["FullSemVer"].ToString();
AppVeyor.UpdateBuildVersion(fullSemVer);
AppVeyor.UpdateBuildVersion(appveyorBuildNumber);
});

Task("__BuildSolutions")
Expand Down Expand Up @@ -186,12 +217,10 @@ Task("__RunTests")
}
});


Task("__CopyOutputToNugetFolder")
.Does(() =>
{
foreach(var project in projectToNugetFolderMap.Keys)
{
foreach(var project in projectToNugetFolderMap.Keys) {
var sourceDir = srcDir + Directory(projectName + "." + project) + Directory("bin") + Directory(configuration);

foreach(var targetFolder in projectToNugetFolderMap[project]) {
Expand All @@ -205,10 +234,25 @@ Task("__CopyOutputToNugetFolder")
CopyFile(nuspecSrcFile, nuspecDestFile);
});

Task("__StronglySignAssemblies")
.Does(() =>
{
//see: https://github.com/brutaldev/StrongNameSigner
var strongNameSignerSettings = new ProcessSettings()
.WithArguments(args => args
.Append("-in")
.AppendQuoted(buildDir)
.Append("-k")
.AppendQuoted(snkFile)
.Append("-l")
.AppendQuoted("Changes"));

StartProcess(strongNameSignerPath, strongNameSignerSettings);
});

Task("__CreateSignedNugetPackage")
.Does(() =>
{
var nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
var packageName = projectName;

Information("Building {0}.{1}.nupkg", packageName, nugetVersion);
Expand All @@ -223,22 +267,6 @@ Task("__CreateSignedNugetPackage")
NuGetPack(nuspecDestFile, nuGetPackSettings);
});

Task("__StronglySignAssemblies")
.Does(() =>
{
//see: https://github.com/brutaldev/StrongNameSigner
var strongNameSignerSettings = new ProcessSettings()
.WithArguments(args => args
.Append("-in")
.AppendQuoted(buildDir)
.Append("-k")
.AppendQuoted(snkFile)
.Append("-l")
.AppendQuoted("Changes"));

StartProcess(strongNameSignerPath, strongNameSignerSettings);
});

//////////////////////////////////////////////////////////////////////
// BUILD TASKS
//////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("Polly.Extensions.Http")]
[assembly: AssemblyVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.5.0")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: CLSCompliant(true)]

[assembly: InternalsVisibleTo("Polly.Extensions.Http.NetStandard11.Specs")]

0 comments on commit 0e01b70

Please sign in to comment.