Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH1369: Implemented MSBuild for VS2017 #1419

Merged
merged 1 commit into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Cake.Common.Tests/Fixtures/Tools/MSBuildRunnerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public MSBuildRunnerFixture(bool is64BitOperativeSystem)
KnownMSBuildPaths.Add("/Program86/MSBuild/12.0/Bin/amd64/MSBuild.exe");
KnownMSBuildPaths.Add("/Program86/MSBuild/14.0/Bin/MSBuild.exe");
KnownMSBuildPaths.Add("/Program86/MSBuild/14.0/Bin/amd64/MSBuild.exe");
KnownMSBuildPaths.Add("/Program86/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should add some tests for community and professional as well here.

KnownMSBuildPaths.Add("/Program86/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/amd64/MSBuild.exe");

// Install all known MSBuild versions.
foreach (var msBuildPath in KnownMSBuildPaths)
Expand Down
17 changes: 17 additions & 0 deletions src/Cake.Common.Tests/Unit/Tools/MSBuild/MSBuildRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ public void Should_Get_Correct_Path_To_MSBuild_Version_35(MSBuildToolVersion ver
Assert.Equal(expected, result.Path.FullPath);
}

[Theory]
[InlineData(MSBuildToolVersion.VS2017, PlatformTarget.x64, false, "/Program86/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/amd64/MSBuild.exe")]
[InlineData(MSBuildToolVersion.VS2017, PlatformTarget.x86, false, "/Program86/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should add some tests for community and professional as well here.

public void Should_Get_Correct_Path_To_MSBuild_Version_15(MSBuildToolVersion version, PlatformTarget target, bool is64BitOperativeSystem, string expected)
{
// Given
var fixture = new MSBuildRunnerFixture(is64BitOperativeSystem);
fixture.Settings.ToolVersion = version;
fixture.Settings.PlatformTarget = target;

// When
var result = fixture.Run();

// Then
Assert.Equal(expected, result.Path.FullPath);
}

[Theory]
[InlineData(MSBuildToolVersion.NET40, PlatformTarget.MSIL, true, "/Windows/Microsoft.NET/Framework64/v4.0.30319/MSBuild.exe")]
[InlineData(MSBuildToolVersion.NET40, PlatformTarget.MSIL, false, "/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe")]
Expand Down
44 changes: 41 additions & 3 deletions src/Cake.Common/Tools/MSBuild/MSBuildResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static FilePath GetMSBuildPath(IFileSystem fileSystem, ICakeEnvironment e
{
var binPath = version == MSBuildToolVersion.Default
? GetHighestAvailableMSBuildVersion(fileSystem, environment, buildPlatform)
: GetMSBuildPath(environment, (MSBuildVersion)version, buildPlatform);
: GetMSBuildPath(fileSystem, environment, (MSBuildVersion)version, buildPlatform);

if (binPath == null)
{
Expand All @@ -29,6 +29,7 @@ private static DirectoryPath GetHighestAvailableMSBuildVersion(IFileSystem fileS
{
var versions = new[]
{
MSBuildVersion.MSBuild15,
MSBuildVersion.MSBuild14,
MSBuildVersion.MSBuild12,
MSBuildVersion.MSBuild4,
Expand All @@ -38,7 +39,7 @@ private static DirectoryPath GetHighestAvailableMSBuildVersion(IFileSystem fileS

foreach (var version in versions)
{
var path = GetMSBuildPath(environment, version, buildPlatform);
var path = GetMSBuildPath(fileSystem, environment, version, buildPlatform);
if (fileSystem.Exist(path))
{
return path;
Expand All @@ -47,10 +48,12 @@ private static DirectoryPath GetHighestAvailableMSBuildVersion(IFileSystem fileS
return null;
}

private static DirectoryPath GetMSBuildPath(ICakeEnvironment environment, MSBuildVersion version, MSBuildPlatform buildPlatform)
private static DirectoryPath GetMSBuildPath(IFileSystem fileSystem, ICakeEnvironment environment, MSBuildVersion version, MSBuildPlatform buildPlatform)
{
switch (version)
{
case MSBuildVersion.MSBuild15:
return GetVisualStudio2017Path(fileSystem, environment, buildPlatform);
case MSBuildVersion.MSBuild14:
return GetVisualStudioPath(environment, buildPlatform, "14.0");
case MSBuildVersion.MSBuild12:
Expand Down Expand Up @@ -85,6 +88,41 @@ private static DirectoryPath GetVisualStudioPath(ICakeEnvironment environment, M
return binPath;
}

private static DirectoryPath GetVisualStudio2017Path(IFileSystem fileSystem, ICakeEnvironment environment,
MSBuildPlatform buildPlatform)
{
var vsEditions = new[]
{
"Enterprise",
"Professional",
"Community"
};

var visualStudio2017Path = environment.GetSpecialPath(SpecialPath.ProgramFilesX86);

foreach (var edition in vsEditions)
{
// Get the bin path.
var binPath = visualStudio2017Path.Combine(string.Concat("Microsoft Visual Studio/2017/", edition, "/MSBuild/15.0/Bin"));
if (fileSystem.Exist(binPath))
{
if (buildPlatform == MSBuildPlatform.Automatic)
{
if (environment.Platform.Is64Bit)
{
binPath = binPath.Combine("amd64");
}
}
if (buildPlatform == MSBuildPlatform.x64)
{
binPath = binPath.Combine("amd64");
}
return binPath;
}
}
return visualStudio2017Path.Combine("Microsoft Visual Studio/2017/Professional/MSBuild/15.0/Bin");
}

private static DirectoryPath GetFrameworkPath(ICakeEnvironment environment, MSBuildPlatform buildPlatform, string version)
{
// Get the Microsoft .NET folder.
Expand Down
5 changes: 5 additions & 0 deletions src/Cake.Common/Tools/MSBuild/MSBuildToolVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ public enum MSBuildToolVersion
/// MSBuild tool version: <c>.NET 4.6</c>
/// </summary>
NET46 = 5,

/// <summary>
/// MSBuild tool version: <c>Visual Studio 2017</c>
/// </summary>
VS2017 = 6
}
}
3 changes: 2 additions & 1 deletion src/Cake.Common/Tools/MSBuild/MSBuildVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal enum MSBuildVersion
MSBuild35 = 2,
MSBuild4 = 3,
MSBuild12 = 4,
MSBuild14 = 5
MSBuild14 = 5,
MSBuild15 = 6
}
}