Skip to content

Commit

Permalink
Fixes for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
wazzamatazz committed Jul 14, 2021
1 parent c117eb7 commit 04afce7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 17 deletions.
24 changes: 24 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,32 @@
<VersionPropertiesInputFile Condition="Exists('$(MSBuildThisFileDirectory)build\version.json')">$(MSBuildThisFileDirectory)build\version.json</VersionPropertiesInputFile>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<CopyrightStartYear>2021</CopyrightStartYear>
</PropertyGroup>

<PropertyGroup>
<!--
IMPORTANT:
This version will always be overridden by the version specified in build\version.json when
building via build.ps1 or build.sh. It is defined here to allow Visual Studio to build with
the solution with the correct version number.
-->
<Version>0.7.0</Version>
</PropertyGroup>

<Choose>
<When Condition=" $([System.DateTime]::UtcNow.Year) > $(CopyrightStartYear) ">
<PropertyGroup>
<Copyright>Copyright © $(CopyrightStartYear)-$([System.DateTime]::UtcNow.Year) $(Authors)</Copyright>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<Copyright>Copyright © $(CopyrightStartYear) $(Authors)</Copyright>
</PropertyGroup>
</Otherwise>
</Choose>

<!-- Extension point to allow Continuous Integration systems to inject their own configuration. -->
<Import Project="CI.props" Condition="Exists('CI.props')" />

Expand Down
9 changes: 0 additions & 9 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
</PropertyGroup>
<Import Project="$(ParentProject)" Condition=" '$(ParentProject)' != '' " />

<ItemGroup>
<!-- MSBuild Extensions (for setting copyright notice and version numbers) -->
<PackageReference Remove="Jaahas.MSBuild.Extensions" />
<PackageReference Include="Jaahas.MSBuild.Extensions" Version="$(JaahasMSBuildExtensionsVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Opt in to .NET analyzer and SourceLink package references by default. Projects in the
samples and test folders are pre-configured to opt out. -->
<PropertyGroup>
Expand Down
27 changes: 22 additions & 5 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Use build.ps1 to run the build script. Command line arguments are documented below.
// Use build.ps1 or build.sh to run the build script. Command line arguments are documented below.
///////////////////////////////////////////////////////////////////////////////////////////////////

const string DefaultSolutionName = "./NRuuviTag.sln";
Expand Down Expand Up @@ -49,7 +49,7 @@ const string DefaultSolutionName = "./NRuuviTag.sln";
// Specifies an additional property to pass to MSBuild during Build and Pack targets. The value
// must be specified using a '<NAME>=<VALUE>' format e.g. --property="NoWarn=CS1591". This
// argument can be specified multiple times.
//
//
///////////////////////////////////////////////////////////////////////////////////////////////////

#addin nuget:?package=Cake.Git&version=1.0.0
Expand All @@ -60,7 +60,7 @@ const string DefaultSolutionName = "./NRuuviTag.sln";
#load "build/build-utilities.cake"

// Get the target that was specified.
var target = Argument("target", "Test");
var target = Argument("target", HasArgument("no-tests") ? "Build" : "Test");


///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -93,11 +93,28 @@ Setup<BuildState>(context => {
var patchVersion = versionJson.Value<int>("Patch");
var versionSuffix = versionJson.Value<string>("PreRelease");
// Compute build number.
// Compute build and version numbers.
var buildCounter = Argument("build-counter", 0);
var buildMetadata = Argument("build-metadata", "");
var branch = GitBranchCurrent(DirectoryPath.FromString(".")).FriendlyName;
state.AssemblyVersion = $"{majorVersion}.{minorVersion}.0.0";
state.AssemblyFileVersion = $"{majorVersion}.{minorVersion}.{patchVersion}.{buildCounter}";
state.InformationalVersion = string.IsNullOrWhiteSpace(versionSuffix)
? $"{majorVersion}.{minorVersion}.{patchVersion}.{buildCounter}+{branch}"
: $"{majorVersion}.{minorVersion}.{patchVersion}-{versionSuffix}.{buildCounter}+{branch}";
if (!string.IsNullOrWhiteSpace(buildMetadata)) {
state.InformationalVersion = string.Concat(state.InformationalVersion, "#", buildMetadata);
}
state.PackageVersion = string.IsNullOrWhiteSpace(versionSuffix)
? $"{majorVersion}.{minorVersion}.{patchVersion}"
: $"{majorVersion}.{minorVersion}.{patchVersion}-{versionSuffix}.{buildCounter}";
state.BuildNumber = string.IsNullOrWhiteSpace(versionSuffix)
? $"{majorVersion}.{minorVersion}.{patchVersion}.{buildCounter}+{branch}"
: $"{majorVersion}.{minorVersion}.{patchVersion}-{versionSuffix}.{buildCounter}+{branch}";
Expand Down Expand Up @@ -242,4 +259,4 @@ Task("Publish")
///////////////////////////////////////////////////////////////////////////////////////////////////


RunTarget(target);
RunTarget(target);
1 change: 0 additions & 1 deletion build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<!-- Dev/Test/Benchmark Packages -->
<PropertyGroup>
<CoverletCollectorVersion>3.0.3</CoverletCollectorVersion>
<JaahasMSBuildExtensionsVersion>1.0.4</JaahasMSBuildExtensionsVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>5.0.3</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftNETTestSdkVersion>16.10.0</MicrosoftNETTestSdkVersion>
<MicrosoftSourceLinkGitHubVersion>1.0.0</MicrosoftSourceLinkGitHubVersion>
Expand Down
12 changes: 12 additions & 0 deletions build/build-state.cake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public class BuildState {
// Specifies if output signing is allowed.
public bool CanSignOutput => SignOutput && ContinuousIntegrationBuild;

// MSBuild AssemblyVersion property value.
public string AssemblyVersion { get; set; }

// MSBuild AssemblyFileVersion property value.
public string AssemblyFileVersion { get; set; }

// MSBuild InformationalVersion property value.
public string InformationalVersion { get; set; }

// MSBuild Version property value.
public string PackageVersion { get; set; }

// Specifies if verbose logging should be used.
public bool Verbose { get; set; }

Expand Down
34 changes: 34 additions & 0 deletions build/build-utilities.cake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public static class BuildUtilities {
// Tell TeamCity the build number if required.
if (buildSystem.IsRunningOnTeamCity) {
buildSystem.TeamCity.SetBuildNumber(buildState.BuildNumber);
buildSystem.TeamCity.SetParameter("system.AssemblyVersion", buildState.AssemblyVersion);
buildSystem.TeamCity.SetParameter("system.AssemblyFileVersion", buildState.AssemblyFileVersion);
buildSystem.TeamCity.SetParameter("system.InformationalVersion", buildState.InformationalVersion);
buildSystem.TeamCity.SetParameter("system.PackageVersion", buildState.PackageVersion);
}
}

Expand Down Expand Up @@ -53,6 +57,30 @@ public static class BuildUtilities {
}


// Adds MSBuild properties from properties specified via the "property" command line argument.
public static void ApplyMSBuildPropertiesFromArguments(DotNetCoreMSBuildSettings settings, ICollection<string> props) {
if (props?.Count == 0) {
return;
}

// We expect each property to be in "NAME=VALUE" format.
var regex = new System.Text.RegularExpressions.Regex(@"^(?<name>.+)=(?<value>.+)$");

foreach (var prop in props) {
if (string.IsNullOrWhiteSpace(prop)) {
continue;
}

var m = regex.Match(prop.Trim());
if (!m.Success) {
continue;
}

settings.Properties[m.Groups["name"].Value] = new List<string> { m.Groups["value"].Value };
}
}


// Adds MSBuild properties from the build state.
public static void ApplyMSBuildProperties(DotNetCoreMSBuildSettings settings, BuildState state) {
if (state.MSBuildProperties?.Count > 0) {
Expand Down Expand Up @@ -82,6 +110,12 @@ public static class BuildUtilities {
if (state.CanSignOutput) {
settings.Properties["SignOutput"] = new List<string> { "True" };
}

// Set version numbers.
settings.Properties["AssemblyVersion"] = new List<string> { state.AssemblyVersion };
settings.Properties["FileVersion"] = new List<string> { state.AssemblyFileVersion };
settings.Properties["Version"] = new List<string> { state.PackageVersion };
settings.Properties["InformationalVersion"] = new List<string> { state.InformationalVersion };
}


Expand Down
4 changes: 2 additions & 2 deletions build/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Major": 0,
"Minor": 6,
"Patch": 1,
"Minor": 7,
"Patch": 0,
"PreRelease": ""
}

0 comments on commit 04afce7

Please sign in to comment.