Skip to content

Commit 2fdae0d

Browse files
committed
fix the runtime check for msbuild testing
1 parent 3503586 commit 2fdae0d

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ItemGroup>
2121
<Compile Include="..\GitVersionCore.Tests\Helpers\DirectoryHelper.cs" Link="Helpers\DirectoryHelper.cs" />
2222
<Compile Include="..\GitVersionCore.Tests\Helpers\GitVersionCoreTestModule.cs" Link="Helpers\GitVersionCoreTestModule.cs" />
23+
<Compile Include="..\GitVersionCore.Tests\Helpers\RuntimeHelper.cs" Link="Helpers\RuntimeHelper.cs" />
2324
<Compile Include="..\GitVersionCore.Tests\Helpers\PathHelper.cs" Link="Helpers\PathHelper.cs" />
2425
<Compile Include="..\GitVersionCore.Tests\Helpers\TestBase.cs" Link="Helpers\TestBase.cs" />
2526
<Compile Include="..\GitVersionCore.Tests\Helpers\TestEffectiveConfiguration.cs" Link="Helpers\TestEffectiveConfiguration.cs" />

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
using Buildalyzer.Environment;
66
using GitTools.Testing;
77
using GitVersionCore.Tests;
8+
using GitVersionCore.Tests.Helpers;
89
using Microsoft.Build.Framework;
910
using Microsoft.Build.Logging;
1011
using Microsoft.Build.Utilities.ProjectCreation;
11-
using NUnit.Framework.Internal;
1212
using StringWriter = System.IO.StringWriter;
1313

1414
namespace GitVersion.MsBuild.Tests.Helpers
@@ -69,12 +69,9 @@ public MsBuildExeFixtureResult Execute()
6969

7070
public void CreateTestProject(Action<ProjectCreator> extendProject)
7171
{
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-
};
72+
var project = RuntimeHelper.IsCoreClr()
73+
? ProjectCreator.Templates.SdkCsproj(ProjectPath)
74+
: ProjectCreator.Templates.LegacyCsproj(ProjectPath, defaultTargets: null, targetFrameworkVersion: "v4.8", toolsVersion: "15.0");
7875

7976
if (project == null) return;
8077

src/GitVersionCore.Tests/Helpers/PathHelper.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ public static string GetCurrentDirectory()
1313

1414
public static string GetExecutable()
1515
{
16-
#if NETFRAMEWORK
17-
var executable = Path.Combine(GetExeDirectory(), "gitversion.exe");
18-
#else
19-
var executable = "dotnet";
20-
#endif
21-
return executable;
16+
return RuntimeHelper.IsCoreClr() ? "dotnet" : Path.Combine(GetExeDirectory(), "gitversion.exe");
2217
}
2318

2419
public static string GetExecutableArgs(string args)
2520
{
26-
#if !NETFRAMEWORK
27-
args = $"{Path.Combine(GetExeDirectory(), "gitversion.dll")} {args}";
28-
#endif
21+
if (RuntimeHelper.IsCoreClr())
22+
{
23+
args = $"{Path.Combine(GetExeDirectory(), "gitversion.dll")} {args}";
24+
}
2925
return args;
3026
}
3127

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace GitVersionCore.Tests.Helpers
2+
{
3+
public static class RuntimeHelper
4+
{
5+
#if !NETFRAMEWORK
6+
private static bool? _isCoreClr;
7+
#endif
8+
9+
public static bool IsCoreClr()
10+
{
11+
#if !NETFRAMEWORK
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/GitVersionExe.Tests/GitVersionExe.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<ItemGroup>
2222
<Compile Include="..\GitVersionCore.Tests\Helpers\DirectoryHelper.cs" Link="Helpers\DirectoryHelper.cs" />
2323
<Compile Include="..\GitVersionCore.Tests\Helpers\PathHelper.cs" Link="Helpers\PathHelper.cs" />
24+
<Compile Include="..\GitVersionCore.Tests\Helpers\RuntimeHelper.cs" Link="Helpers\RuntimeHelper.cs" />
2425
<Compile Include="..\GitVersionCore.Tests\Helpers\TestEffectiveConfiguration.cs" Link="Helpers\TestEffectiveConfiguration.cs" />
2526
<Compile Include="..\GitVersionCore.Tests\Helpers\TestEnvironment.cs" Link="Helpers\TestEnvironment.cs" />
2627
<Compile Include="..\GitVersionCore.Tests\Helpers\TestFileSystem.cs" Link="Helpers\TestFileSystem.cs" />

0 commit comments

Comments
 (0)