@@ -11,69 +11,61 @@ var configuration = Argument<string>("configuration", "Release");
1111
1212#Tool "xunit.runner.console"
1313#Tool "GitVersion.CommandLine"
14- #Tool "Brutal.Dev.StrongNameSigner"
1514
1615//////////////////////////////////////////////////////////////////////
1716// EXTERNAL NUGET LIBRARIES
1817//////////////////////////////////////////////////////////////////////
1918
2019#addin "Cake.FileHelpers"
20+ #addin nuget : ? package= Cake . Yaml
21+ #addin nuget: ? package = YamlDotNet & version = 5.2 .1
2122
2223///////////////////////////////////////////////////////////////////////////////
2324// GLOBAL VARIABLES
2425///////////////////////////////////////////////////////////////////////////////
2526
2627var projectName = "Polly.Caching.Distributed" ;
27- var keyName = "Polly.snk" ;
2828
2929var solutions = GetFiles( "./**/*.sln" ) ;
3030var solutionPaths = solutions. Select( solution => solution . GetDirectory ( ) ) ;
3131
3232var srcDir = Directory( "./src" ) ;
33- var buildDir = Directory ( "./build" ) ;
3433var artifactsDir = Directory( "./artifacts" ) ;
3534var testResultsDir = artifactsDir + Directory ( "test-results" ) ;
3635
3736// NuGet
38- var nuspecExtension = ".nuspec" ;
39- var nuspecFolder = "nuget-package" ;
40- var nuspecSrcFile = srcDir + File ( projectName + nuspecExtension ) ;
41- var nuspecDestFile = buildDir + File ( projectName + nuspecExtension ) ;
42- var nupkgDestDir = artifactsDir + Directory ( nuspecFolder ) ;
43- var snkFile = srcDir + File ( keyName ) ;
44-
45- var projectToNugetFolderMap = new Dictionary < string , string [ ] > ( ) {
46- { "NetStandard11" , new [ ] { "netstandard1.1" } } ,
47- { "NetStandard20" , new [ ] { "netstandard2.0" } } ,
48- } ;
37+ var nupkgDestDir = artifactsDir + Directory ( "nuget-package" ) ;
4938
5039// Gitversion
5140var gitVersionPath = ToolsExePath( "GitVersion.exe" ) ;
5241Dictionary < string , object > gitVersionOutput ;
42+ var gitVersionConfigFilePath = "./GitVersionConfig.yaml" ;
5343
5444// Versioning
5545string nugetVersion;
5646string appveyorBuildNumber;
5747string assemblyVersion;
5848string assemblySemver;
5949
60- // StrongNameSigner
61- var strongNameSignerPath = ToolsExePath ( "StrongNameSigner.Console.exe" ) ;
62-
50+ ///////////////////////////////////////////////////////////////////////////////
51+ // INNER CLASSES
52+ ///////////////////////////////////////////////////////////////////////////////
53+ class GitVersionConfigYaml
54+ {
55+ public string NextVersion { get ; set ; }
56+ }
6357
6458///////////////////////////////////////////////////////////////////////////////
6559// SETUP / TEARDOWN
6660///////////////////////////////////////////////////////////////////////////////
6761
6862Setup( _ =>
6963{
70- // ASCII art via: http://patorjk.com/software/taag/?#p=display&f=Graceful&t=Polly.Caching.Distributed%0A
7164 Information ( "" ) ;
72- Information ( @"" ) ;
73- Information ( @" ____ __ __ __ _ _ ___ __ ___ _ _ __ __ _ ___ ____ __ ____ ____ ____ __ ____ _ _ ____ ____ ____ " ) ;
74- Information ( @"( _ \ / \ ( ) ( ) ( \/ ) / __) / _\ / __)/ )( \( )( ( \ / __) ( \( )/ ___)(_ _)( _ \( )( _ \/ )( \(_ _)( __)( \" ) ;
75- Information ( @" ) __/( O )/ (_/\/ (_/\ ) /_( (__ / \( (__ ) __ ( )( / /( (_ \ _ ) D ( )( \___ \ )( ) / )( ) _ () \/ ( )( ) _) ) D (" ) ;
76- Information ( @"(__) \__/ \____/\____/(__/(_)\___)\_/\_/ \___)\_)(_/(__)\_)__) \___/(_)(____/(__)(____/ (__) (__\_)(__)(____/\____/ (__) (____)(____/" ) ;
65+ Information ( "----------------------------------------" ) ;
66+ Information ( "Starting the cake build script" ) ;
67+ Information ( "Building: " + projectName ) ;
68+ Information ( "----------------------------------------" ) ;
7769 Information ( "" ) ;
7870} ) ;
7971
@@ -90,7 +82,6 @@ Task("__Clean")
9082 . Does ( ( ) =>
9183{
9284 DirectoryPath [ ] cleanDirectories = new DirectoryPath [ ] {
93- buildDir ,
9485 testResultsDir ,
9586 nupkgDestDir ,
9687 artifactsDir
@@ -103,8 +94,7 @@ Task("__Clean")
10394 foreach ( var path in solutionPaths )
10495 {
10596 Information ( "Cleaning {0}" , path ) ;
106- CleanDirectories ( path + "/**/bin/" + configuration ) ;
107- CleanDirectories ( path + "/**/obj/" + configuration ) ;
97+ DotNetCoreClean ( path . ToString ( ) ) ;
10898 }
10999} ) ;
110100
@@ -114,7 +104,7 @@ Task("__RestoreNugetPackages")
114104 foreach ( var solution in solutions )
115105 {
116106 Information ( "Restoring NuGet Packages for {0}" , solution ) ;
117- NuGetRestore ( solution ) ;
107+ DotNetCoreRestore ( solution . ToString ( ) ) ;
118108 }
119109} ) ;
120110
@@ -124,13 +114,29 @@ Task("__UpdateAssemblyVersionInformation")
124114 var gitVersionSettings = new ProcessSettings ( )
125115 . SetRedirectStandardOutput ( true ) ;
126116
127- IEnumerable < string > outputLines ;
128- StartProcess ( gitVersionPath , gitVersionSettings , out outputLines ) ;
117+ try {
118+ IEnumerable < string > outputLines ;
119+ StartProcess ( gitVersionPath , gitVersionSettings , out outputLines ) ;
120+
121+ var output = string . Join ( "\n " , outputLines ) ;
122+ gitVersionOutput = Newtonsoft . Json . JsonConvert . DeserializeObject < Dictionary < string , object > > ( output ) ;
123+ }
124+ catch
125+ {
126+ Information ( "Error reading git version information. Build may be running outside of a git repo. Falling back to version specified in " + gitVersionConfigFilePath ) ;
127+
128+ string gitVersionYamlString = System . IO . File . ReadAllText ( gitVersionConfigFilePath ) ;
129+ GitVersionConfigYaml deserialized = DeserializeYaml < GitVersionConfigYaml > ( gitVersionYamlString . Replace ( "next-version" , "NextVersion" ) ) ;
130+ string gitVersionConfig = deserialized . NextVersion ;
129131
130- var output = string . Join ( "\n " , outputLines ) ;
131- gitVersionOutput = Newtonsoft . Json . JsonConvert . DeserializeObject < Dictionary < string , object > > ( output ) ;
132+ gitVersionOutput = new Dictionary < string , object > {
133+ { "NuGetVersion" , gitVersionConfig + "-NotFromGitRepo" } ,
134+ { "FullSemVer" , gitVersionConfig } ,
135+ { "AssemblySemVer" , gitVersionConfig } ,
136+ { "Major" , gitVersionConfig . Split ( '.' ) [ 0 ] } ,
137+ } ;
132138
133- Information ( "Updated GlobalAssemblyInfo" ) ;
139+ }
134140
135141 Information ( "" ) ;
136142 Information ( "Obtained raw version info for package versioning:" ) ;
@@ -159,24 +165,22 @@ Task("__UpdateDotNetStandardAssemblyVersionNumber")
159165
160166 var attributeToValueMap = new Dictionary < string , string > ( ) {
161167 { "AssemblyVersion" , assemblyVersion } ,
162- { "AssemblyFileVersion" , assemblySemver } ,
163- { "AssemblyInformationalVersion" , assemblySemver } ,
168+ { "FileVersion" , assemblySemver } ,
169+ { "InformationalVersion" , assemblySemver } ,
170+ { "Version" , nugetVersion } ,
171+ { "PackageVersion" , nugetVersion } ,
164172 } ;
165173
166- var assemblyInfosToUpdate = GetFiles ( "./src/**/Properties/AssemblyInfo.cs" )
167- . Select ( f => f . FullPath )
168- . Where ( f => ! f . Contains ( "Specs" ) ) ;
174+ var csproj = File ( "./src/" + projectName + "/" + projectName + ".csproj" ) ;
169175
170176 foreach ( var attributeMap in attributeToValueMap ) {
171177 var attribute = attributeMap . Key ;
172178 var value = attributeMap . Value ;
173179
174- foreach ( var assemblyInfo in assemblyInfosToUpdate ) {
175- var replacedFiles = ReplaceRegexInFiles ( assemblyInfo , attribute + "[(]\" .*\" [)]" , attribute + "(\" " + value + "\" )" ) ;
176- if ( ! replacedFiles . Any ( ) )
177- {
178- throw new Exception ( $ "{ attribute } attribute could not be updated in { assemblyInfo } .") ;
179- }
180+ var replacedFiles = ReplaceRegexInFiles ( csproj , $@ "\<{ attribute } \>[^\<]*\</{ attribute } \>", $@ "<{ attribute } >{ value } </{ attribute } >") ;
181+ if ( ! replacedFiles . Any ( ) )
182+ {
183+ throw new Exception ( $ "{ attribute } version could not be updated in { csproj } .") ;
180184 }
181185 }
182186
@@ -196,13 +200,14 @@ Task("__BuildSolutions")
196200 {
197201 Information ( "Building {0}" , solution ) ;
198202
199- MSBuild ( solution , settings =>
200- settings
201- . SetConfiguration ( configuration )
202- . WithProperty ( "TreatWarningsAsErrors" , "true" )
203- . UseToolVersion ( MSBuildToolVersion . VS2017 )
204- . SetVerbosity ( Verbosity . Minimal )
205- . SetNodeReuse ( false ) ) ;
203+ var dotNetCoreBuildSettings = new DotNetCoreBuildSettings {
204+ Configuration = configuration ,
205+ Verbosity = DotNetCoreVerbosity . Minimal ,
206+ NoRestore = true ,
207+ MSBuildSettings = new DotNetCoreMSBuildSettings { TreatAllWarningsAs = MSBuildTreatAllWarningsAs . Error }
208+ } ;
209+
210+ DotNetCoreBuild ( solution . ToString ( ) , dotNetCoreBuildSettings ) ;
206211 }
207212} ) ;
208213
@@ -217,54 +222,20 @@ Task("__RunTests")
217222 }
218223} ) ;
219224
220- Task ( "__CopyOutputToNugetFolder" )
221- . Does ( ( ) =>
222- {
223- foreach ( var project in projectToNugetFolderMap . Keys ) {
224- var sourceDir = srcDir + Directory ( projectName + "." + project ) + Directory ( "bin" ) + Directory ( configuration ) ;
225-
226- foreach ( var targetFolder in projectToNugetFolderMap [ project ] ) {
227- var destDir = buildDir + Directory ( "lib" ) ;
228-
229- Information ( "Copying {0} -> {1}." , sourceDir , destDir ) ;
230- CopyDirectory ( sourceDir , destDir ) ;
231- }
232- }
233-
234- CopyFile ( nuspecSrcFile , nuspecDestFile ) ;
235- } ) ;
236-
237- Task ( "__StronglySignAssemblies" )
238- . Does ( ( ) =>
239- {
240- //see: https://github.com/brutaldev/StrongNameSigner
241- var strongNameSignerSettings = new ProcessSettings ( )
242- . WithArguments ( args => args
243- . Append ( "-in" )
244- . AppendQuoted ( buildDir )
245- . Append ( "-k" )
246- . AppendQuoted ( snkFile )
247- . Append ( "-l" )
248- . AppendQuoted ( "Changes" ) ) ;
249-
250- StartProcess ( strongNameSignerPath , strongNameSignerSettings ) ;
251- } ) ;
252-
253225Task( "__CreateSignedNugetPackage" )
254226 . Does ( ( ) =>
255227{
256228 var packageName = projectName ;
257229
258230 Information ( "Building {0}.{1}.nupkg" , packageName , nugetVersion ) ;
259231
260- var nuGetPackSettings = new NuGetPackSettings {
261- Id = packageName ,
262- Title = packageName ,
263- Version = nugetVersion ,
232+ var dotNetCorePackSettings = new DotNetCorePackSettings {
233+ Configuration = configuration ,
234+ NoBuild = true ,
264235 OutputDirectory = nupkgDestDir
265236 } ;
266237
267- NuGetPack ( nuspecDestFile , nuGetPackSettings ) ;
238+ DotNetCorePack ( $@ " { srcDir } \ { projectName } .sln" , dotNetCorePackSettings ) ;
268239} ) ;
269240
270241//////////////////////////////////////////////////////////////////////
@@ -279,8 +250,6 @@ Task("Build")
279250 . IsDependentOn ( "__UpdateAppVeyorBuildNumber" )
280251 . IsDependentOn ( "__BuildSolutions" )
281252 . IsDependentOn ( "__RunTests" )
282- . IsDependentOn ( "__CopyOutputToNugetFolder" )
283- . IsDependentOn ( "__StronglySignAssemblies" )
284253 . IsDependentOn ( "__CreateSignedNugetPackage" ) ;
285254
286255///////////////////////////////////////////////////////////////////////////////
@@ -301,6 +270,6 @@ RunTarget(target);
301270//////////////////////////////////////////////////////////////////////
302271
303272string ToolsExePath( string exeFileName ) {
304- var exePath = System . IO . Directory . GetFiles ( @".\Tools " , exeFileName , SearchOption . AllDirectories ) . FirstOrDefault ( ) ;
273+ var exePath = System. IO . Directory . GetFiles ( @"./tools " , exeFileName , SearchOption . AllDirectories ) . FirstOrDefault ( ) ;
305274 return exePath;
306275}
0 commit comments