Skip to content

Commit a82c96c

Browse files
committed
fix the runtime check for msbuild testing
1 parent fed5dc2 commit a82c96c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace GitVersion.MsBuild.Tests.Helpers
2+
{
3+
internal static class EnvironmentHelper
4+
{
5+
#if NETCORE || NETCOREAPP
6+
private static bool? _isCoreClr;
7+
#endif
8+
9+
public static bool IsCoreClr()
10+
{
11+
#if NETCORE || NETCOREAPP
12+
_isCoreClr ??= System.Environment.Version.Major >= 5
13+
|| System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith(".NET Core");
14+
return _isCoreClr.Value;
15+
#else
16+
return false;
17+
#endif
18+
}
19+
}
20+
}

src/GitVersion.MsBuild.Tests/Helpers/MsBuildExeFixture.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.Build.Framework;
99
using Microsoft.Build.Logging;
1010
using Microsoft.Build.Utilities.ProjectCreation;
11-
using NUnit.Framework.Internal;
1211
using StringWriter = System.IO.StringWriter;
1312

1413
namespace GitVersion.MsBuild.Tests.Helpers
@@ -69,12 +68,9 @@ public MsBuildExeFixtureResult Execute()
6968

7069
public void CreateTestProject(Action<ProjectCreator> extendProject)
7170
{
72-
var project = RuntimeFramework.CurrentFramework.Runtime switch
73-
{
74-
RuntimeType.NetCore => ProjectCreator.Templates.SdkCsproj(ProjectPath),
75-
RuntimeType.Net => ProjectCreator.Templates.LegacyCsproj(ProjectPath, defaultTargets: null, targetFrameworkVersion: "v4.8", toolsVersion: "15.0"),
76-
_ => null
77-
};
71+
var project = EnvironmentHelper.IsCoreClr()
72+
? ProjectCreator.Templates.SdkCsproj(ProjectPath)
73+
: ProjectCreator.Templates.LegacyCsproj(ProjectPath, defaultTargets: null, targetFrameworkVersion: "v4.8", toolsVersion: "15.0");
7874

7975
if (project == null) return;
8076

0 commit comments

Comments
 (0)