Skip to content

Commit e8a557e

Browse files
GitHubSync update
1 parent e45b0a1 commit e8a557e

File tree

6 files changed

+102
-74
lines changed

6 files changed

+102
-74
lines changed

deployment/cake/lib-generic.cake

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,7 @@ private static bool IsDotNetCoreProject(BuildContext buildContext, string projec
517517
var lowerCase = line.ToLower();
518518
if (lowerCase.Contains("targetframework"))
519519
{
520-
if (lowerCase.Contains("netcore"))
521-
{
522-
isDotNetCore = true;
523-
break;
524-
}
525-
526-
if (lowerCase.Contains("net5") ||
527-
lowerCase.Contains("net6") ||
528-
lowerCase.Contains("net7") ||
529-
lowerCase.Contains("net8"))
520+
if (IsDotNetCoreTargetFramework(buildContext, lowerCase))
530521
{
531522
isDotNetCore = true;
532523
break;
@@ -542,6 +533,30 @@ private static bool IsDotNetCoreProject(BuildContext buildContext, string projec
542533

543534
//-------------------------------------------------------------
544535

536+
private static bool IsDotNetCoreTargetFramework(BuildContext buildContext, string targetFramework)
537+
{
538+
var lowerCase = targetFramework.ToLower();
539+
540+
if (lowerCase.Contains("netcore"))
541+
{
542+
return true;
543+
}
544+
545+
if (lowerCase.Contains("net5") ||
546+
lowerCase.Contains("net6") ||
547+
lowerCase.Contains("net7") ||
548+
lowerCase.Contains("net8") ||
549+
lowerCase.Contains("net9") ||
550+
lowerCase.Contains("net10"))
551+
{
552+
return true;
553+
}
554+
555+
return false;
556+
}
557+
558+
//-------------------------------------------------------------
559+
545560
private static bool ShouldProcessProject(BuildContext buildContext, string projectName,
546561
bool checkDeployment = true)
547562
{
@@ -660,7 +675,7 @@ private static string CreateInlinedProjectXml(BuildContext buildContext, string
660675

661676
//-------------------------------------------------------------
662677

663-
private static List<string> GetProjectRuntimesIdentifiers(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List<string> runtimeIdentifiersToInvestigate)
678+
private static List<string> GetProjectRuntimesIdentifiers(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList<string> runtimeIdentifiersToInvestigate)
664679
{
665680
var projectFileContents = System.IO.File.ReadAllText(solutionOrProjectFileName.FullPath)?.ToLower();
666681

@@ -670,7 +685,7 @@ private static List<string> GetProjectRuntimesIdentifiers(BuildContext buildCont
670685
{
671686
if (!string.IsNullOrWhiteSpace(runtimeIdentifier))
672687
{
673-
if (!projectFileContents.Contains(runtimeIdentifier.ToLower()))
688+
if (!projectFileContents.Contains(runtimeIdentifier, StringComparison.OrdinalIgnoreCase))
674689
{
675690
buildContext.CakeContext.Information("Project '{0}' does not support runtime identifier '{1}', removing from supported runtime identifiers list", solutionOrProjectFileName, runtimeIdentifier);
676691
continue;

deployment/cake/lib-nuget.cake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ private static void RestoreNuGetPackages(BuildContext buildContext, Cake.Core.IO
5454

5555
var sources = SplitSeparatedList(buildContext.General.NuGet.PackageSources, ';');
5656

57-
var runtimeIdentifiers = new List<string>(new []
57+
var runtimeIdentifiers = new []
5858
{
59+
"win-x86",
5960
"win-x64",
61+
"win-arm64",
6062
"browser-wasm"
61-
});
63+
};
6264

6365
var supportedRuntimeIdentifiers = GetProjectRuntimesIdentifiers(buildContext, solutionOrProjectFileName, runtimeIdentifiers);
6466

@@ -68,7 +70,7 @@ private static void RestoreNuGetPackages(BuildContext buildContext, Cake.Core.IO
6870

6971
//-------------------------------------------------------------
7072

71-
private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List<string> sources, List<string> runtimeIdentifiers)
73+
private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList<string> sources, IReadOnlyList<string> runtimeIdentifiers)
7274
{
7375
if (!buildContext.General.NuGet.RestoreUsingNuGet)
7476
{
@@ -91,7 +93,7 @@ private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Ca
9193

9294
if (sources.Count > 0)
9395
{
94-
nuGetRestoreSettings.Source = sources;
96+
nuGetRestoreSettings.Source = sources.ToList();
9597
}
9698

9799
buildContext.CakeContext.NuGetRestore(solutionOrProjectFileName, nuGetRestoreSettings);
@@ -104,7 +106,7 @@ private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Ca
104106

105107
//-------------------------------------------------------------
106108

107-
private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List<string> sources, List<string> runtimeIdentifiers)
109+
private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList<string> sources, IReadOnlyList<string> runtimeIdentifiers)
108110
{
109111
if (!buildContext.General.NuGet.RestoreUsingDotNetRestore)
110112
{
@@ -141,7 +143,7 @@ private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildCon
141143

142144
if (sources.Count > 0)
143145
{
144-
restoreSettings.Sources = sources;
146+
restoreSettings.Sources = sources.ToList();
145147
}
146148

147149
using (buildContext.CakeContext.UseDiagnosticVerbosity())

deployment/cake/tasks.cake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
// It probably means the tool is not correctly installed.
3737
// `dotnet tool install --global dotnet-sonarscanner --ignore-failed-sources`
3838
//#tool "nuget:?package=MSBuild.SonarQube.Runner.Tool&version=4.8.0"
39-
#tool "nuget:?package=dotnet-sonarscanner&version=7.1.1"
39+
#tool "nuget:?package=dotnet-sonarscanner&version=8.0.3"
4040

4141
//-------------------------------------------------------------
4242
// BACKWARDS COMPATIBILITY CODE - START
@@ -382,9 +382,9 @@ Task("Build")
382382
Verbose = false,
383383
Silent = true,
384384

385-
// Support waiting for the quality gate
386385
ArgumentCustomization = args => args
387386
.Append("/d:sonar.qualitygate.wait=true")
387+
.Append("/d:sonar.scanner.scanAll=false")
388388
};
389389

390390
if (!string.IsNullOrWhiteSpace(buildContext.General.SonarQube.Organization))

deployment/cake/tests-nunit.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.18.1"
1+
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.18.2"
22

33
//-------------------------------------------------------------
44

deployment/cake/tests-variables.cake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class TestsContext : BuildContextWithItemsBase
1111

1212
public string Framework { get; set; }
1313
public string TargetFramework { get; set; }
14+
public string OperatingSystem { get; set; }
1415
public string ProcessBit { get; set; }
1516

1617
protected override void ValidateContext()
@@ -47,6 +48,7 @@ private TestsContext InitializeTestsContext(BuildContext buildContext, IBuildCon
4748

4849
Framework = buildContext.BuildServer.GetVariable("TestFramework", "nunit", showValue: true),
4950
TargetFramework = buildContext.BuildServer.GetVariable("TestTargetFramework", "", showValue: true),
51+
OperatingSystem = buildContext.BuildServer.GetVariable("TestOperatingSystem", "win", showValue: true),
5052
ProcessBit = buildContext.BuildServer.GetVariable("TestProcessBit", "X64", showValue: true)
5153
};
5254

deployment/cake/tests.cake

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -137,63 +137,70 @@ private static void RunUnitTests(BuildContext buildContext, string projectName)
137137

138138
var ranTests = false;
139139
var failed = false;
140-
var testTargetFramework = GetTestTargetFramework(buildContext, projectName);
140+
var testTargetFrameworks = GetTestTargetFrameworks(buildContext, projectName);
141141

142142
try
143143
{
144-
if (IsDotNetCoreProject(buildContext, projectName))
144+
foreach (var testTargetFramework in testTargetFrameworks)
145145
{
146-
buildContext.CakeContext.Information($"Project '{projectName}' is a .NET core project, using 'dotnet test' to run the unit tests");
147-
148-
var projectFileName = GetProjectFileName(buildContext, projectName);
149-
150-
var dotNetTestSettings = new DotNetTestSettings
151-
{
152-
Configuration = buildContext.General.Solution.ConfigurationName,
153-
// Loggers = new []
154-
// {
155-
// "nunit;LogFilePath=test-result.xml"
156-
// },
157-
NoBuild = true,
158-
NoLogo = true,
159-
NoRestore = true,
160-
OutputDirectory = System.IO.Path.Combine(GetProjectOutputDirectory(buildContext, projectName), testTargetFramework),
161-
ResultsDirectory = testResultsDirectory
162-
};
163-
164-
if (IsNUnitTestProject(buildContext, projectName))
165-
{
166-
dotNetTestSettings.ArgumentCustomization = args => args
167-
.Append($"-- NUnit.TestOutputXml={testResultsDirectory}");
168-
}
146+
LogSeparator(buildContext.CakeContext, "Running tests for target framework {0}", testTargetFramework);
169147

170-
if (IsXUnitTestProject(buildContext, projectName))
148+
if (IsDotNetCoreTargetFramework(buildContext, testTargetFramework))
171149
{
172-
var outputFileName = System.IO.Path.Combine(testResultsDirectory, $"{projectName}.xml");
150+
buildContext.CakeContext.Information($"Project '{projectName}' is a .NET core project, using 'dotnet test' to run the unit tests");
151+
152+
var projectFileName = GetProjectFileName(buildContext, projectName);
153+
154+
var dotNetTestSettings = new DotNetTestSettings
155+
{
156+
Configuration = buildContext.General.Solution.ConfigurationName,
157+
// Loggers = new []
158+
// {
159+
// "nunit;LogFilePath=test-result.xml"
160+
// },
161+
NoBuild = true,
162+
NoLogo = true,
163+
NoRestore = true,
164+
OutputDirectory = System.IO.Path.Combine(GetProjectOutputDirectory(buildContext, projectName), testTargetFramework),
165+
ResultsDirectory = testResultsDirectory
166+
};
167+
168+
if (IsNUnitTestProject(buildContext, projectName))
169+
{
170+
dotNetTestSettings.ArgumentCustomization = args => args
171+
.Append($"-- NUnit.TestOutputXml={testResultsDirectory}");
172+
}
173+
174+
if (IsXUnitTestProject(buildContext, projectName))
175+
{
176+
var outputFileName = System.IO.Path.Combine(testResultsDirectory, $"{projectName}.xml");
177+
178+
dotNetTestSettings.ArgumentCustomization = args => args
179+
.Append($"-l:trx;LogFileName={outputFileName}");
180+
}
181+
182+
var processBit = buildContext.Tests.ProcessBit.ToLower();
183+
if (!string.IsNullOrWhiteSpace(processBit))
184+
{
185+
dotNetTestSettings.Runtime = $"{buildContext.Tests.OperatingSystem}-{processBit}";
186+
}
187+
188+
buildContext.CakeContext.Information($"Runtime: '{dotNetTestSettings.Runtime}'");
189+
190+
buildContext.CakeContext.DotNetTest(projectFileName, dotNetTestSettings);
173191

174-
dotNetTestSettings.ArgumentCustomization = args => args
175-
.Append($"-l:trx;LogFileName={outputFileName}");
192+
ranTests = true;
176193
}
177-
178-
var processBit = buildContext.Tests.ProcessBit.ToLower();
179-
if (!string.IsNullOrWhiteSpace(processBit))
194+
else
180195
{
181-
dotNetTestSettings.Runtime = $"win-{processBit}";
182-
}
183-
184-
buildContext.CakeContext.DotNetTest(projectFileName, dotNetTestSettings);
185-
186-
ranTests = true;
187-
}
188-
else
189-
{
190-
buildContext.CakeContext.Information($"Project '{projectName}' is a .NET project, using '{buildContext.Tests.Framework} runner' to run the unit tests");
196+
buildContext.CakeContext.Information($"Project '{projectName}' is a .NET project, using '{buildContext.Tests.Framework} runner' to run the unit tests");
191197

192-
if (IsNUnitTestProject(buildContext, projectName))
193-
{
194-
RunTestsUsingNUnit(buildContext, projectName, testTargetFramework, testResultsDirectory);
198+
if (IsNUnitTestProject(buildContext, projectName))
199+
{
200+
RunTestsUsingNUnit(buildContext, projectName, testTargetFramework, testResultsDirectory);
195201

196-
ranTests = true;
202+
ranTests = true;
203+
}
197204
}
198205
}
199206
}
@@ -273,28 +280,30 @@ private static bool IsXUnitTestProject(BuildContext buildContext, string project
273280

274281
//-------------------------------------------------------------
275282

276-
private static string GetTestTargetFramework(BuildContext buildContext, string projectName)
283+
private static IReadOnlyList<string> GetTestTargetFrameworks(BuildContext buildContext, string projectName)
277284
{
278285
// Step 1: if defined, use defined value
279286
var testTargetFramework = buildContext.Tests.TargetFramework;
280287
if (!string.IsNullOrWhiteSpace(testTargetFramework))
281288
{
282289
buildContext.CakeContext.Information("Using test target framework '{0}', specified via the configuration", testTargetFramework);
283290

284-
return testTargetFramework;
291+
return new []
292+
{
293+
testTargetFramework
294+
};
285295
}
286296

287-
buildContext.CakeContext.Information("Test target framework not specified, auto detecting test target framework");
297+
buildContext.CakeContext.Information("Test target framework not specified, auto detecting test target frameworks");
288298

289299
var targetFrameworks = GetTargetFrameworks(buildContext, projectName);
290-
testTargetFramework = targetFrameworks.FirstOrDefault();
291300

292-
buildContext.CakeContext.Information("Auto detected test target framework '{0}'", testTargetFramework);
301+
buildContext.CakeContext.Information("Auto detected test target frameworks '{0}'", string.Join(", ", targetFrameworks));
293302

294-
if (string.IsNullOrWhiteSpace(testTargetFramework))
303+
if (targetFrameworks.Length == 0)
295304
{
296305
throw new Exception(string.Format("Test target framework could not automatically be detected for project '{0]'", projectName));
297306
}
298307

299-
return testTargetFramework;
308+
return targetFrameworks;
300309
}

0 commit comments

Comments
 (0)