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

(#3794) fix detection of VS2022 BuildTools #3795

Merged
merged 1 commit into from
Jan 22, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ public void Should_Get_Correct_Path_To_MSBuild_Version_17(MSBuildToolVersion ver
}

[Theory]
[InlineData(MSBuildToolVersion.VS2022, PlatformTarget.x64, PlatformFamily.Windows, false, "/Program/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe")]
[InlineData(MSBuildToolVersion.VS2022, PlatformTarget.x86, PlatformFamily.Windows, false, "/Program/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/MSBuild.exe")]
[InlineData(MSBuildToolVersion.VS2022, PlatformTarget.x64, PlatformFamily.Windows, false, "/Program86/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe")]
[InlineData(MSBuildToolVersion.VS2022, PlatformTarget.x86, PlatformFamily.Windows, false, "/Program86/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/MSBuild.exe")]
public void Should_Get_Correct_Path_To_MSBuild_Version_17_When_Only_Build_Tools_Are_Installed(MSBuildToolVersion version, PlatformTarget target, PlatformFamily family, bool is64BitOperativeSystem, string expected)
{
// Given
Expand All @@ -186,8 +186,8 @@ public void Should_Get_Correct_Path_To_MSBuild_Version_17_When_Only_Build_Tools_

fixture.GivenDefaultToolDoNotExist();
fixture.GivenMSBuildIsNotInstalled();
fixture.FileSystem.CreateFile("/Program/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe");
fixture.FileSystem.CreateFile("/Program/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/MSBuild.exe");
fixture.FileSystem.CreateFile("/Program86/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe");
fixture.FileSystem.CreateFile("/Program86/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/MSBuild.exe");

// When
var result = fixture.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void Should_Use_VSTest_From_Tool_Path_If_Provided_On_Windows(string toolP
[InlineData("/ProgramFiles/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TestWindow/vstest.console.exe")]
[InlineData("/ProgramFiles/Microsoft Visual Studio/2022/Professional/Common7/IDE/CommonExtensions/Microsoft/TestWindow/vstest.console.exe")]
[InlineData("/ProgramFiles/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow/vstest.console.exe")]
[InlineData("/ProgramFiles/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/TestWindow/vstest.console.exe")]
[InlineData("/ProgramFilesX86/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/TestWindow/vstest.console.exe")]
public void Should_Use_Available_Tool_Path(string existingToolPath)
{
// Given
Expand Down
10 changes: 7 additions & 3 deletions src/Cake.Common/Tools/VisualStudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ internal static FilePath GetYearAndEditionToolPath(ICakeEnvironment environment,

internal static DirectoryPath GetYearAndEditionRootPath(ICakeEnvironment environment, string year, string edition)
{
var programFiles = year == "2017" || year == "2019"
? environment.GetSpecialPath(SpecialPath.ProgramFilesX86)
: environment.GetSpecialPath(SpecialPath.ProgramFiles);
var programFiles = (year, edition) switch
{
("2022", "BuildTools") => environment.GetSpecialPath(SpecialPath.ProgramFilesX86),
("2022", _) => environment.GetSpecialPath(SpecialPath.ProgramFiles),
(_, _) => environment.GetSpecialPath(SpecialPath.ProgramFilesX86),
};

return programFiles.Combine($"Microsoft Visual Studio/{year}/{edition}");
}

Expand Down