55using Nuke . Common . ProjectModel ;
66using Nuke . Common . Tools . DotNet ;
77using Nuke . Common . Tools . GitHub ;
8- using Nuke . Common . Tools . NuGet ;
98using Nuke . Common . Utilities . Collections ;
109using Octokit ;
1110using Octokit . Internal ;
1514using System . IO ;
1615using System . Linq ;
1716using static Nuke . Common . Tools . DotNet . DotNetTasks ;
18- using static Nuke . Common . Tools . NuGet . NuGetTasks ;
1917using Project = Nuke . Common . ProjectModel . Project ;
2018
2119class Build : NukeBuild
@@ -46,8 +44,6 @@ class Build : NukeBuild
4644
4745 AbsolutePath SourceDirectory => RootDirectory / "src" ;
4846
49- AbsolutePath BuildDirectory => SourceDirectory / TargetProjectName / "bin" / Configuration ;
50-
5147 AbsolutePath ResultDirectory => RootDirectory / "bin" / Version ;
5248
5349 AbsolutePath NugetDirectory => ResultDirectory / "nuget" ;
@@ -141,6 +137,8 @@ protected override void OnBuildInitialized()
141137 var settings = s
142138 . SetProjectFile ( Solution )
143139 . SetConfiguration ( Configuration )
140+ . SetVersion ( Version )
141+ . SetContinuousIntegrationBuild ( IsServerBuild )
144142 . EnableNoRestore ( ) ;
145143
146144 if ( ! String . IsNullOrEmpty ( AngleSharpVersion ) )
@@ -161,6 +159,7 @@ protected override void OnBuildInitialized()
161159 var settings = s
162160 . SetProjectFile ( Solution )
163161 . SetConfiguration ( Configuration )
162+ . SetProperty ( "Version" , Version )
164163 . EnableNoRestore ( )
165164 . EnableNoBuild ( ) ;
166165
@@ -173,39 +172,30 @@ protected override void OnBuildInitialized()
173172 } ) ;
174173 } ) ;
175174
176- Target CopyFiles => _ => _
175+ // The package is produced by `dotnet pack` straight from the project, so the dependency
176+ // groups follow the actual TargetFrameworks instead of a hand-maintained nuspec.
177+ Target CreatePackage => _ => _
177178 . DependsOn ( Compile )
178179 . Executes ( ( ) =>
179180 {
180- foreach ( var item in TargetFrameworks )
181+ DotNetPack ( s =>
181182 {
182- var targetDir = NugetDirectory / "lib" / item ;
183- var srcDir = BuildDirectory / item ;
184-
185- ( srcDir / $ "{ TargetProjectName } .dll") . Copy ( targetDir / $ "{ TargetProjectName } .dll", ExistsPolicy . FileOverwriteIfNewer ) ;
186- ( srcDir / $ "{ TargetProjectName } .pdb") . Copy ( targetDir / $ "{ TargetProjectName } .pdb", ExistsPolicy . FileOverwriteIfNewer ) ;
187- ( srcDir / $ "{ TargetProjectName } .xml") . Copy ( targetDir / $ "{ TargetProjectName } .xml", ExistsPolicy . FileOverwriteIfNewer ) ;
188- }
183+ var settings = s
184+ . SetProject ( TargetProject )
185+ . SetConfiguration ( Configuration )
186+ . SetVersion ( Version )
187+ . SetOutputDirectory ( NugetDirectory )
188+ . SetContinuousIntegrationBuild ( IsServerBuild )
189+ . EnableNoRestore ( )
190+ . EnableNoBuild ( ) ;
189191
190- ( SourceDirectory / $ " { TargetProjectName } .nuspec" ) . Copy ( NugetDirectory / $ " { TargetProjectName } .nuspec" , ExistsPolicy . FileOverwriteIfNewer ) ;
191- ( RootDirectory / "logo.png" ) . Copy ( NugetDirectory / "logo.png" , ExistsPolicy . FileOverwriteIfNewer ) ;
192- ( RootDirectory / "README.md" ) . Copy ( NugetDirectory / "README.md" , ExistsPolicy . FileOverwriteIfNewer ) ;
193- } ) ;
192+ if ( ! String . IsNullOrEmpty ( AngleSharpVersion ) )
193+ {
194+ settings = settings . SetProperty ( "AngleSharpVersion" , AngleSharpVersion ) ;
195+ }
194196
195- Target CreatePackage => _ => _
196- . DependsOn ( CopyFiles )
197- . Executes ( ( ) =>
198- {
199- var nuspec = NugetDirectory / $ "{ TargetProjectName } .nuspec";
200-
201- NuGetPack ( _ => _
202- . SetTargetPath ( nuspec )
203- . SetVersion ( Version )
204- . SetOutputDirectory ( NugetDirectory )
205- . SetSymbols ( true )
206- . SetSymbolPackageFormat ( "snupkg" )
207- . AddProperty ( "Configuration" , Configuration )
208- ) ;
197+ return settings ;
198+ } ) ;
209199 } ) ;
210200
211201 Target PublishPackage => _ => _
@@ -221,9 +211,10 @@ protected override void OnBuildInitialized()
221211 throw new BuildAbortedException ( "Could not resolve the NuGet API key." ) ;
222212 }
223213
214+ // Pushing the .nupkg also uploads the matching .snupkg next to it.
224215 foreach ( var nupkg in NugetDirectory . GlobFiles ( "*.nupkg" ) )
225216 {
226- NuGetPush ( s => s
217+ DotNetNuGetPush ( s => s
227218 . SetTargetPath ( nupkg )
228219 . SetSource ( "https://api.nuget.org/v3/index.json" )
229220 . SetApiKey ( apiKey ) ) ;
0 commit comments