1
1
#tool "nuget:?package=GitVersion.CommandLine"
2
2
3
+ using System . Text . RegularExpressions ;
4
+
3
5
//////////////////////////////////////////////////////////////////////
4
6
// ARGUMENTS
5
7
//////////////////////////////////////////////////////////////////////
@@ -10,6 +12,12 @@ var pushPackages = Argument("PushPackages", "false") == "true";
10
12
bool isPrerelease = false ;
11
13
GitVersion versionInfo = null ;
12
14
15
+ var projectsToBuild = new string [ ] {
16
+ "./src/Cofoundry.Plugins.ErrorLogging/Cofoundry.Plugins.ErrorLogging.csproj" ,
17
+ "./src/Cofoundry.Plugins.ErrorLogging.Admin/Cofoundry.Plugins.ErrorLogging.Admin.csproj" ,
18
+ } ;
19
+
20
+
13
21
//////////////////////////////////////////////////////////////////////
14
22
// PREPARATION
15
23
//////////////////////////////////////////////////////////////////////
@@ -27,15 +35,8 @@ Task("Clean")
27
35
CleanDirectory ( nugetPackageDir ) ;
28
36
CleanDirectories ( "./src/**/bin/" + configuration ) ;
29
37
CleanDirectories ( "./src/**/obj/" + configuration ) ;
30
- CleanDirectory ( "./src/Cofoundry.Plugins.ErrorLogging.Admin/bin/" ) ;
31
38
} ) ;
32
39
33
- Task ( "Restore-NuGet-Packages" )
34
- . IsDependentOn ( "Clean" )
35
- . Does ( ( ) =>
36
- {
37
- NuGetRestore ( "./src/Cofoundry.Plugins.ErrorLogging.sln" ) ;
38
- } ) ;
39
40
40
41
Task ( "Patch-Assembly-Version" )
41
42
. IsDependentOn ( "Clean" )
@@ -45,49 +46,65 @@ Task("Patch-Assembly-Version")
45
46
UpdateAssemblyInfo = false
46
47
} ) ;
47
48
48
- Information ( "Building version {0} of Cofoundry.Plugins.ErrorLogging. " , versionInfo . InformationalVersion ) ;
49
+ Information ( "Building version {0} of Cofoundry." , versionInfo . InformationalVersion ) ;
49
50
50
51
isPrerelease = ! string . IsNullOrEmpty ( versionInfo . PreReleaseNumber ) ;
51
52
52
- var file = "./src/SolutionInfo.cs" ;
53
- CreateAssemblyInfo ( file , new AssemblyInfoSettings {
54
- Version = versionInfo . AssemblySemVer ,
55
- FileVersion = versionInfo . MajorMinorPatch + ".0" ,
56
- InformationalVersion = versionInfo . InformationalVersion ,
57
- Copyright = "Copyright © Cofoundry.org " + DateTime . Now . Year
58
- } ) ;
53
+ // Patch the version number so it's picked up when dependent projects are references
54
+ // as nuget dependencies. Can't find a better way to do this.
55
+ // Also this needs to run before DotNetCoreRestore for some reason (cached?)
56
+ var file = MakeAbsolute ( File ( "./src/Directory.Build.props" ) ) ;
57
+ var xml = System . IO . File . ReadAllText ( file . FullPath , Encoding . UTF8 ) ;
58
+ xml = Regex . Replace ( xml , @"(<Version>)(.+)(<\/Version>)" , "${1}" + versionInfo . NuGetVersion + "${3}" ) ;
59
+ System . IO . File . WriteAllText ( file . FullPath , xml , Encoding . UTF8 ) ;
60
+ } ) ;
61
+
62
+ Task ( "Restore-NuGet-Packages" )
63
+ . IsDependentOn ( "Patch-Assembly-Version" )
64
+ . Does ( ( ) =>
65
+ {
66
+ foreach ( var projectToBuild in projectsToBuild )
67
+ {
68
+ DotNetCoreRestore ( projectToBuild ) ;
69
+ }
59
70
} ) ;
60
71
61
72
Task ( "Build" )
62
73
. IsDependentOn ( "Restore-NuGet-Packages" )
63
- . IsDependentOn ( "Patch-Assembly-Version" )
64
74
. Does ( ( ) =>
65
75
{
66
- if ( IsRunningOnWindows ( ) )
76
+
77
+ var settings = new DotNetCoreBuildSettings
78
+ {
79
+ Configuration = configuration ,
80
+ ArgumentCustomization = args => args
81
+ . Append ( "/p:NuGetVersion=" + versionInfo . NuGetVersion )
82
+ . Append ( "/p:AssemblyVersion=" + versionInfo . AssemblySemVer )
83
+ . Append ( "/p:FileVersion=" + versionInfo . MajorMinorPatch + ".0" )
84
+ . Append ( "/p:InformationalVersion=" + versionInfo . InformationalVersion )
85
+ . Append ( "/p:Copyright=" + "\" Copyright © Cofoundry.org " + DateTime . Now . Year + "\" " )
86
+ } ;
87
+
88
+ foreach ( var projectToBuild in projectsToBuild )
67
89
{
68
- // Use MSBuild
69
- MSBuild ( "./src/Cofoundry.Plugins.ErrorLogging.sln" , settings => settings . SetConfiguration ( configuration ) ) ;
90
+ DotNetCoreBuild ( projectToBuild , settings ) ;
70
91
}
71
92
} ) ;
72
93
73
94
Task ( "Pack" )
74
95
. IsDependentOn ( "Build" )
75
96
. Does ( ( ) =>
76
97
{
77
- var nugetFilePaths = GetFiles ( "./src/Cofoundry.*/*.nuspec" ) ;
78
-
79
- var nuGetPackSettings = new NuGetPackSettings
80
- {
81
- Version = versionInfo . NuGetVersion ,
82
- OutputDirectory = nugetPackageDir ,
83
- Verbosity = NuGetVerbosity . Detailed ,
84
- ArgumentCustomization = args => args . Append ( "-Prop Configuration=" + configuration )
85
- } ;
98
+ var settings = new DotNetCorePackSettings
99
+ {
100
+ Configuration = configuration ,
101
+ OutputDirectory = "./artifacts/" ,
102
+ NoBuild = true
103
+ } ;
86
104
87
- foreach ( var path in nugetFilePaths )
105
+ foreach ( var projectToBuild in projectsToBuild )
88
106
{
89
- Information ( "Packing:" + path ) ;
90
- NuGetPack ( path , nuGetPackSettings ) ;
107
+ DotNetCorePack ( projectToBuild , settings ) ;
91
108
}
92
109
} ) ;
93
110
0 commit comments