@@ -8,6 +8,7 @@ using System;
8
8
using System. Text . RegularExpressions ;
9
9
using System. Linq ;
10
10
using Cake. Common . Tools . DotNetCore . DotNetCoreVerbosity ;
11
+ using Path = Cake . Core . IO . Path ;
11
12
12
13
const string defaultTarget = "Default" ;
13
14
var target = Argument ( "target" , defaultTarget ) ;
@@ -65,7 +66,7 @@ Task("Restore")
65
66
66
67
Task( "Build" )
67
68
. IsDependentOn ( "Restore" )
68
- . Does ( ( ) =>
69
+ . Does < BuildConfig > ( ( buildConfig ) =>
69
70
{
70
71
var settings = new DotNetCoreBuildSettings
71
72
{
@@ -77,6 +78,14 @@ Task("Build")
77
78
{ "SourceRevisionId" , gitVersion . Sha }
78
79
}
79
80
} ;
81
+
82
+ if ( buildConfig . IsReleaseMode )
83
+ {
84
+ Console . WriteLine ( "Build continuousIntegration is enabled" ) ;
85
+ settings . MSBuildSettings = new DotNetCoreMSBuildSettings ( ) ;
86
+ // configure deterministic build for better compatibility with debug symbols (used in Package/Build tasks). Affects: *.nupkg
87
+ settings . MSBuildSettings . SetContinuousIntegrationBuild ( continuousIntegrationBuild : true ) ;
88
+ }
80
89
DotNetCoreBuild ( solutionFullPath , settings ) ;
81
90
} ) ;
82
91
@@ -122,9 +131,8 @@ Task("BuildArtifacts")
122
131
Task( "Test" )
123
132
. IsDependentOn ( "Build" )
124
133
. DoesForEach (
125
- GetFiles ( "./**/*.Tests.csproj" )
126
- . Where ( name => ! name . ToString ( ) . Contains ( "Atlas" ) ) ,
127
- testProject =>
134
+ items : GetFiles ( "./**/*.Tests.csproj" ) . Where ( name => ! name . ToString ( ) . Contains ( "Atlas" ) ) ,
135
+ action : ( BuildConfig buildConfig , Path testProject ) =>
128
136
{
129
137
if ( Environment . GetEnvironmentVariable ( "MONGODB_API_VERSION" ) != null &&
130
138
testProject . ToString ( ) . Contains ( "Legacy" ) )
@@ -159,14 +167,10 @@ Task("Test")
159
167
NoRestore = true ,
160
168
Configuration = configuration ,
161
169
Loggers = CreateLoggers ( ) ,
162
- ArgumentCustomization = args => args . Append ( "-- RunConfiguration.TargetPlatform=x64" )
170
+ ArgumentCustomization = args => args . Append ( "-- RunConfiguration.TargetPlatform=x64" ) ,
171
+ Framework = buildConfig . Framework
163
172
} ;
164
- switch ( target . ToLowerInvariant ( ) ) // target can be not only moniker related
165
- {
166
- case "testnet472" : settings . Framework = "net472" ; break ;
167
- case "testnetstandard20" : settings . Framework = "netcoreapp2.1" ; break ;
168
- case "testnetstandard21" : settings . Framework = "netcoreapp3.1" ; break ;
169
- }
173
+
170
174
DotNetCoreTest (
171
175
testProject . FullPath ,
172
176
settings
@@ -315,24 +319,19 @@ Task("TestOcsp")
315
319
Task( "TestGssapi" )
316
320
. IsDependentOn ( "Build" )
317
321
. DoesForEach (
318
- GetFiles ( "./**/MongoDB.Driver.Tests.csproj" ) ,
319
- testProject =>
322
+ items : GetFiles ( "./**/MongoDB.Driver.Tests.csproj" ) ,
323
+ action : ( BuildConfig buildConfig , Path testProject ) =>
320
324
{
321
325
var settings = new DotNetCoreTestSettings
322
326
{
323
327
NoBuild = true ,
324
328
NoRestore = true ,
325
329
Configuration = configuration ,
326
330
ArgumentCustomization = args => args . Append ( "-- RunConfiguration.TargetPlatform=x64" ) ,
327
- Filter = "Category=\" GssapiMechanism\" "
331
+ Filter = "Category=\" GssapiMechanism\" " ,
332
+ Framework = buildConfig . Framework
328
333
} ;
329
334
330
- switch ( target . ToLowerInvariant ( ) ) // target can be not only moniker related
331
- {
332
- case "testgssapinet472" : settings . Framework = "net472" ; break ;
333
- case "testgssapinetstandard20" : settings . Framework = "netcoreapp2.1" ; break ;
334
- case "testgssapinetstandard21" : settings . Framework = "netcoreapp3.1" ; break ;
335
- }
336
335
DotNetCoreTest (
337
336
testProject . FullPath ,
338
337
settings
@@ -346,23 +345,19 @@ Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
346
345
Task( "TestServerless" )
347
346
. IsDependentOn ( "Build" )
348
347
. DoesForEach (
349
- GetFiles ( "./**/MongoDB.Driver.Tests.csproj" ) ,
350
- testProject =>
348
+ items : GetFiles ( "./**/MongoDB.Driver.Tests.csproj" ) ,
349
+ action : ( BuildConfig buildConfig , Path testProject ) =>
351
350
{
352
351
var settings = new DotNetCoreTestSettings
353
352
{
354
353
NoBuild = true ,
355
354
NoRestore = true ,
356
355
Configuration = configuration ,
357
356
ArgumentCustomization = args => args . Append ( "-- RunConfiguration.TargetPlatform=x64" ) ,
358
- Filter = "Category=\" Serverless\" "
357
+ Filter = "Category=\" Serverless\" " ,
358
+ Framework = buildConfig . Framework
359
359
} ;
360
- switch ( target . ToLowerInvariant ( ) ) // target can be not only moniker related
361
- {
362
- case "testserverlessnet472" : settings . Framework = "net472" ; break ;
363
- case "testserverlessnetstandard20" : settings . Framework = "netcoreapp2.1" ; break ;
364
- case "testserverlessnetstandard21" : settings . Framework = "netcoreapp3.1" ; break ;
365
- }
360
+
366
361
DotNetCoreTest (
367
362
testProject . FullPath ,
368
363
settings
@@ -376,24 +371,19 @@ Task("TestServerlessNetStandard21").IsDependentOn("TestServerless");
376
371
Task( "TestLoadBalanced" )
377
372
. IsDependentOn ( "Build" )
378
373
. DoesForEach (
379
- GetFiles ( "./**/*.Tests.csproj" ) ,
380
- testProject =>
374
+ items : GetFiles ( "./**/*.Tests.csproj" ) ,
375
+ action : ( BuildConfig buildConfig , Path testProject ) =>
381
376
{
382
377
var settings = new DotNetCoreTestSettings
383
378
{
384
379
NoBuild = true ,
385
380
NoRestore = true ,
386
381
Configuration = configuration ,
387
382
ArgumentCustomization = args => args . Append ( "-- RunConfiguration.TargetPlatform=x64" ) ,
388
- Filter = "Category=\" SupportLoadBalancing\" "
383
+ Filter = "Category=\" SupportLoadBalancing\" " ,
384
+ Framework = buildConfig . Framework
389
385
} ;
390
386
391
- switch ( target . ToLowerInvariant ( ) ) // target can be not only moniker related
392
- {
393
- case "testloadbalancednetstandard20" : settings . Framework = "netcoreapp2.1" ; break ;
394
- case "testloadbalancednetstandard21" : settings . Framework = "netcoreapp3.1" ; break ;
395
- }
396
-
397
387
DotNetCoreTest (
398
388
testProject . FullPath ,
399
389
settings
@@ -406,8 +396,8 @@ Task("TestLoadBalancedNetStandard21").IsDependentOn("TestLoadBalanced");
406
396
Task( "TestCsfleWithMockedKms" )
407
397
. IsDependentOn ( "Build" )
408
398
. DoesForEach (
409
- GetFiles ( "./**/*.Tests.csproj" ) ,
410
- testProject =>
399
+ items : GetFiles ( "./**/*.Tests.csproj" ) ,
400
+ action : ( BuildConfig buildConfig , Path testProject ) =>
411
401
{
412
402
var settings = new DotNetCoreTestSettings
413
403
{
@@ -416,16 +406,10 @@ Task("TestCsfleWithMockedKms")
416
406
Configuration = configuration ,
417
407
Loggers = CreateLoggers ( ) ,
418
408
ArgumentCustomization = args => args . Append ( "-- RunConfiguration.TargetPlatform=x64" ) ,
419
- Filter = "Category=\" CSFLE\" "
409
+ Filter = "Category=\" CSFLE\" " ,
410
+ Framework = buildConfig . Framework
420
411
} ;
421
412
422
- switch ( target . ToLowerInvariant ( ) ) // target can be not only moniker related
423
- {
424
- case "testcsflewithmockedkmsnet472" : settings . Framework = "net472" ; break ;
425
- case "testcsflewithmockedkmsnetstandard20" : settings . Framework = "netcoreapp2.1" ; break ;
426
- case "testcsflewithmockedkmsnetstandard21" : settings . Framework = "netcoreapp3.1" ; break ;
427
- }
428
-
429
413
DotNetCoreTest (
430
414
testProject . FullPath ,
431
415
settings
@@ -535,9 +519,11 @@ Task("PackageNugetPackages")
535
519
{
536
520
Configuration = configuration ,
537
521
OutputDirectory = artifactsPackagesDirectory ,
538
- NoBuild = true ,
522
+ NoBuild = true , // SetContinuousIntegrationBuild is enabled for nupkg on the Build step
539
523
IncludeSymbols = true ,
540
524
MSBuildSettings = new DotNetCoreMSBuildSettings ( )
525
+ // configure deterministic build for better compatibility with debug symbols (used in Package/Build tasks). Affects: *.snupkg
526
+ . SetContinuousIntegrationBuild ( continuousIntegrationBuild : true )
541
527
. WithProperty ( "PackageVersion" , gitVersion . LegacySemVer )
542
528
} ;
543
529
DotNetCorePack ( projectPath , settings ) ;
@@ -798,8 +784,36 @@ Task("TestsPackaging")
798
784
} )
799
785
. DeferOnError ( ) ;
800
786
787
+ Setup< BuildConfig > (
788
+ setupContext =>
789
+ {
790
+ var lowerTarget = target . ToLowerInvariant ( ) ;
791
+ var framework = lowerTarget switch
792
+ {
793
+ string s when s . StartsWith ( "test" ) && s . EndsWith ( "net472" ) => "net472" ,
794
+ string s when s . StartsWith ( "test" ) && s . EndsWith ( "netstandard20" ) => "netcoreapp2.1" ,
795
+ string s when s . StartsWith ( "test" ) && s . EndsWith ( "netstandard21" ) => "netcoreapp3.1" ,
796
+ _ => null
797
+ } ;
798
+ var isReleaseMode = lowerTarget . StartsWith ( "package" ) || lowerTarget == "release" ;
799
+ Console . WriteLine ( $ "Framework: { framework ?? "null (not set)" } , IsReleaseMode: { isReleaseMode } ") ;
800
+ return new BuildConfig ( isReleaseMode , framework ) ;
801
+ } ) ;
802
+
801
803
RunTarget( target ) ;
802
804
805
+ public class BuildConfig
806
+ {
807
+ public bool IsReleaseMode { get ; }
808
+ public string Framework { get ; }
809
+
810
+ public BuildConfig( bool isReleaseMode , string framework )
811
+ {
812
+ IsReleaseMode = isReleaseMode;
813
+ Framework = framework;
814
+ }
815
+ }
816
+
803
817
string [ ] CreateLoggers ( )
804
818
{
805
819
var testResultsFile = outputDirectory. Combine ( "test-results" ) . Combine ( $ "TEST-{ target . ToLowerInvariant ( ) } -{ DateTimeOffset . UtcNow . ToUnixTimeMilliseconds ( ) } .xml") ;
0 commit comments