33#addin "nuget:?package=Cake.Incubator"
44#tool "nuget:?package=GitVersion.CommandLine"
55#tool "nuget:?package=xunit.runner.console"
6- #load buildhelpers . cake
76
87using System . Text . RegularExpressions ;
98using System . Linq ;
@@ -16,7 +15,7 @@ var gitVersion = GitVersion();
1615var solutionDirectory = MakeAbsolute ( Directory ( "./" ) ) ;
1716var artifactsDirectory = solutionDirectory . Combine ( "artifacts" ) ;
1817var artifactsBinDirectory = artifactsDirectory . Combine ( "bin" ) ;
19- var artifactsBinNet45Directory = artifactsBinDirectory . Combine ( "net45 " ) ;
18+ var artifactsBinNet452Directory = artifactsBinDirectory . Combine ( "net452 " ) ;
2019var artifactsBinNetStandard15Directory = artifactsBinDirectory . Combine ( "netstandard1.5" ) ;
2120var artifactsDocsDirectory = artifactsDirectory . Combine ( "docs" ) ;
2221var artifactsDocsApiDocsDirectory = artifactsDocsDirectory . Combine ( "ApiDocs-" + gitVersion . LegacySemVer ) ;
@@ -47,16 +46,7 @@ Task("TestAndPackage")
4746 . IsDependentOn ( "Test" )
4847 . IsDependentOn ( "Package" ) ;
4948
50- Task ( "Clean" )
51- . Does ( ( ) =>
52- {
53- CleanDirectory ( artifactsDirectory ) ;
54- CleanDirectories ( "./**/obj" ) ;
55- CleanDirectories ( $ "./**/bin/{ configuration } ") ;
56- } ) ;
57-
5849Task ( "Restore" )
59- . IsDependentOn ( "Clean" )
6050 . Does ( ( ) =>
6151 {
6252 DotNetCoreRestore ( solutionFullPath ) ;
@@ -79,6 +69,43 @@ Task("Build")
7969 DotNetCoreBuild ( solutionFullPath , settings ) ;
8070 } ) ;
8171
72+ Task ( "BuildArtifacts" )
73+ . IsDependentOn ( "Build" )
74+ . Does ( ( ) =>
75+ {
76+ foreach ( var targetFramework in new [ ] { "net452" , "netstandard1.5" } )
77+ {
78+ var toDirectory = artifactsBinDirectory . Combine ( targetFramework ) ;
79+ CleanDirectory ( toDirectory ) ;
80+
81+ var projects = new [ ] { "MongoDB.Bson" , "MongoDB.Driver.Core" , "MongoDB.Driver" , "MongoDB.Driver.Legacy" , "MongoDB.Driver.GridFS" } ;
82+ foreach ( var project in projects )
83+ {
84+ var fromDirectory = srcDirectory . Combine ( project ) . Combine ( "bin" ) . Combine ( configuration ) . Combine ( targetFramework ) ;
85+
86+ var fileNames = new List < string > ( ) ;
87+ foreach ( var extension in new [ ] { "dll" , "pdb" , "xml" } )
88+ {
89+ var fileName = $ "{ project } .{ extension } ";
90+ fileNames . Add ( fileName ) ;
91+ }
92+
93+ // DnsClient.dll is needed by Sandcastle
94+ if ( targetFramework == "net452" && project == "MongoDB.Driver.Core" )
95+ {
96+ fileNames . Add ( "DnsClient.dll" ) ;
97+ }
98+
99+ foreach ( var fileName in fileNames )
100+ {
101+ var fromFile = fromDirectory . CombineWithFilePath ( fileName ) ;
102+ var toFile = toDirectory . CombineWithFilePath ( fileName ) ;
103+ CopyFile ( fromFile , toFile ) ;
104+ }
105+ }
106+ }
107+ } ) ;
108+
82109Task ( "Test" )
83110 . IsDependentOn ( "Build" )
84111 . DoesForEach (
@@ -119,7 +146,7 @@ Task("Docs")
119146 . IsDependentOn ( "RefDocs" ) ;
120147
121148Task ( "ApiDocs" )
122- . IsDependentOn ( "Build " )
149+ . IsDependentOn ( "BuildArtifacts " )
123150 . Does ( ( ) =>
124151 {
125152 EnsureDirectoryExists ( artifactsDocsApiDocsDirectory ) ;
@@ -205,7 +232,7 @@ Task("Package")
205232 . IsDependentOn ( "PackageNugetPackages" ) ;
206233
207234Task ( "PackageReleaseZipFile" )
208- . IsDependentOn ( "Build " )
235+ . IsDependentOn ( "BuildArtifacts " )
209236 . IsDependentOn ( "ApiDocs" )
210237 . Does ( ( ) =>
211238 {
@@ -216,10 +243,10 @@ Task("PackageReleaseZipFile")
216243 EnsureDirectoryExists ( stagingDirectory ) ;
217244 CleanDirectory ( stagingDirectory ) ;
218245
219- var stagingNet45Directory = stagingDirectory . Combine ( "net45 " ) ;
220- CopyDirectory ( artifactsBinNet45Directory , stagingNet45Directory ) ;
221- DeleteFile ( stagingNet45Directory . CombineWithFilePath ( "DnsClient.dll" ) ) ;
222- DeleteFile ( stagingNet45Directory . CombineWithFilePath ( "DnsClient.xml" ) ) ;
246+ var stagingNet452Directory = stagingDirectory . Combine ( "net452 " ) ;
247+ CopyDirectory ( artifactsBinNet452Directory , stagingNet452Directory ) ;
248+ DeleteFile ( stagingNet452Directory . CombineWithFilePath ( "DnsClient.dll" ) ) ;
249+ DeleteFile ( stagingNet452Directory . CombineWithFilePath ( "DnsClient.xml" ) ) ;
223250
224251 var stagingNetStandard15Directory = stagingDirectory . Combine ( "netstandard1.5" ) ;
225252 CopyDirectory ( artifactsBinNetStandard15Directory , stagingNetStandard15Directory ) ;
0 commit comments