Skip to content

Commit e4f6630

Browse files
Fix CI after image update to a stable VS by @Youssef1313 in #6863 (backport to rel/4.0) (#6913)
Co-authored-by: Youssef1313 <youssefvictor00@gmail.com>
1 parent 703b71f commit e4f6630

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

  • test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceTestBase.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,32 @@ public static void ClassCleanup()
151151
private protected static async Task<string> FindMsbuildWithVsWhereAsync(CancellationToken cancellationToken)
152152
{
153153
string vswherePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft Visual Studio", "Installer", "vswhere.exe");
154+
string path = await RunAndGetSingleLineStandardOutputAsync(vswherePath, "-find MSBuild\\**\\Bin\\MSBuild.exe", cancellationToken);
155+
156+
if (string.Equals(Environment.GetEnvironmentVariable("TF_BUILD"), "true", StringComparison.OrdinalIgnoreCase))
157+
{
158+
// WORKAROUND: Allow SDK to consider preview versions when running under a stable VS.
159+
// https://github.com/dotnet/sdk/issues/51525
160+
string installationVersion = await RunAndGetSingleLineStandardOutputAsync(vswherePath, "-property installationVersion", cancellationToken);
161+
string instanceId = await RunAndGetSingleLineStandardOutputAsync(vswherePath, "-property instanceId", cancellationToken);
162+
var version = Version.Parse(installationVersion);
163+
string directory = Path.Combine(
164+
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
165+
"Microsoft",
166+
"VisualStudio",
167+
version.Major + ".0_" + instanceId);
168+
Directory.CreateDirectory(directory);
169+
string settingsFilePath = Path.Combine(directory, "sdk.txt");
170+
File.WriteAllText(settingsFilePath, "UsePreviews=True");
171+
}
172+
173+
return path;
174+
}
175+
176+
private static async Task<string> RunAndGetSingleLineStandardOutputAsync(string vswherePath, string arg, CancellationToken cancellationToken)
177+
{
154178
var commandLine = new TestInfrastructure.CommandLine();
155-
await commandLine.RunAsync($"\"{vswherePath}\" -latest -prerelease -requires Microsoft.Component.MSBuild -find MSBuild\\**\\Bin\\MSBuild.exe", cancellationToken: cancellationToken);
179+
await commandLine.RunAsync($"\"{vswherePath}\" -latest -prerelease -requires Microsoft.Component.MSBuild {arg}", cancellationToken: cancellationToken);
156180

157181
string? path = null;
158182
using (var stringReader = new StringReader(commandLine.StandardOutput))

0 commit comments

Comments
 (0)