Skip to content

Commit 2422660

Browse files
committed
Add runtime switch between MSBuild and xbuild
1 parent 87495e3 commit 2422660

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System.IO;
22
using GitTools.Testing;
3+
using GitVersion;
34
using NUnit.Framework;
45
using Shouldly;
56

67
[TestFixture]
78
public class ExecCmdLineArgumentTest
89
{
9-
const string MsBuild = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe";
10-
11-
1210
[Test]
1311
public void RunExecViaCommandLine()
1412
{
@@ -26,7 +24,7 @@ public void RunExecViaCommandLine()
2624
</Target>
2725
</Project>";
2826
File.WriteAllText(buildFile, buildFileContent);
29-
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, MsBuild, "RunExecViaCommandLine.proj /target:OutputResults");
27+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, SpecifiedArgumentRunner.BuildTool, "RunExecViaCommandLine.proj /target:OutputResults");
3028

3129
result.ExitCode.ShouldBe(0);
3230
result.Log.ShouldContain("GitVersion_FullSemVer: 1.2.4+1");

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ namespace GitVersion
99

1010
class SpecifiedArgumentRunner
1111
{
12-
const string MsBuild = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe";
12+
private static readonly bool runningOnMono = Type.GetType("Mono.Runtime") != null;
13+
public static readonly string BuildTool = runningOnMono? "xbuild" : @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe";
1314

1415
public static void Run(Arguments arguments, IFileSystem fileSystem)
1516
{
17+
Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows"));
18+
1619
var noFetch = arguments.NoFetch;
1720
var authentication = arguments.Authentication;
1821
var targetPath = arguments.TargetPath;
@@ -74,14 +77,14 @@ static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionV
7477
{
7578
if (string.IsNullOrEmpty(args.Proj)) return false;
7679

77-
Logger.WriteInfo(string.Format("Launching {0} \"{1}\" {2}", MsBuild, args.Proj, args.ProjArgs));
80+
Logger.WriteInfo(string.Format("Launching build tool {0} \"{1}\" {2}", BuildTool, args.Proj, args.ProjArgs));
7881
var results = ProcessHelper.Run(
7982
Logger.WriteInfo, Logger.WriteError,
80-
null, MsBuild, string.Format("\"{0}\" {1}", args.Proj, args.ProjArgs), workingDirectory,
83+
null, BuildTool, string.Format("\"{0}\" {1}", args.Proj, args.ProjArgs), workingDirectory,
8184
GetEnvironmentalVariables(variables));
8285

8386
if (results != 0)
84-
throw new WarningException("MsBuild execution failed, non-zero return code");
87+
throw new WarningException(string.Format("{0} execution failed, non-zero return code", runningOnMono ? "XBuild" : "MSBuild"));
8588

8689
return true;
8790
}

0 commit comments

Comments
 (0)