Skip to content

Commit e847512

Browse files
committed
Use upstream MSBuilderLocator
1 parent e233f14 commit e847512

File tree

5 files changed

+5
-66
lines changed

5 files changed

+5
-66
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
This file was deleted.

Bootstrap/Bootstrap.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<RootNamespace>TestMyCode.CSharp.Bootstrap</RootNamespace>
77
<Nullable>enable</Nullable>
88
<AssemblyName>TestMyCode.CSharp.Bootstrap</AssemblyName>
9+
<RollForward>LatestMajor</RollForward>
910
</PropertyGroup>
1011

1112
<PropertyGroup>
@@ -17,12 +18,12 @@
1718
</PropertyGroup>
1819

1920
<ItemGroup>
21+
<PackageReference Include="Microsoft.Build.Locator" Version="1.4.1" />
2022
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
2123
</ItemGroup>
2224

2325
<ItemGroup>
2426
<ProjectReference Include="..\Core\Core.csproj" />
25-
<ProjectReference Include="..\MSBuildLocator\src\MSBuildLocator\Microsoft.Build.Locator.csproj" />
2627
</ItemGroup>
2728

2829
</Project>

Bootstrap/Program.cs

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
using System.CommandLine;
44
using System.CommandLine.Invocation;
55
using System.IO;
6-
using System.Linq;
7-
using System.Reflection;
8-
using System.Runtime.CompilerServices;
9-
using System.Runtime.Loader;
106
using System.Text.Json;
117
using System.Threading.Tasks;
128
using Microsoft.Build.Locator;
@@ -20,12 +16,7 @@ public static class Program
2016
{
2117
public static async Task Main(string[] args)
2218
{
23-
if (!Program.FindMsBuild())
24-
{
25-
return;
26-
}
27-
28-
Program.SetMsBuildDepsResolver();
19+
MSBuildLocator.RegisterDefaults();
2920

3021
RootCommand rootCommand = Program.GenerateCommands();
3122
rootCommand.Handler = CommandHandler.Create(async (bool generatePointsFile, bool runTests, DirectoryInfo? projectDir, FileInfo? outputFile) =>
@@ -129,47 +120,5 @@ private static RootCommand GenerateCommands()
129120
}, description: "The output file used to write results.")
130121
};
131122
}
132-
133-
private static bool FindMsBuild()
134-
{
135-
string? msbuildPath = Environment.GetEnvironmentVariable("MSBUILD_EXE_PATH");
136-
if (msbuildPath is not null)
137-
{
138-
return true;
139-
}
140-
141-
VisualStudioInstance? vsInstance = MSBuildLocator.QueryVisualStudioInstances(VisualStudioInstanceQueryOptions.Default)
142-
.FirstOrDefault(i => i.Version.Major == Environment.Version.Major && i.Version.Minor == Environment.Version.Minor);
143-
if (vsInstance is not null)
144-
{
145-
MSBuildLocator.RegisterInstance(vsInstance);
146-
147-
return true;
148-
}
149-
150-
Console.WriteLine($"No environment variable MSBUILD_EXE_PATH has been set and we were unable to locate it automatically! You need to install SDK for {Environment.Version.ToString(2)}");
151-
152-
return false;
153-
}
154-
155-
private static void SetMsBuildDepsResolver()
156-
{
157-
string msbuildDir = Path.GetDirectoryName(Environment.GetEnvironmentVariable("MSBUILD_EXE_PATH"))!;
158-
159-
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
160-
{
161-
AssemblyName name = new AssemblyName(args.Name);
162-
163-
string assemblyName = $"{name.Name}.dll";
164-
string sdkFileName = Path.Combine(msbuildDir, assemblyName);
165-
166-
if (File.Exists(sdkFileName))
167-
{
168-
return Assembly.LoadFile(sdkFileName);
169-
}
170-
171-
return null;
172-
};
173-
}
174123
}
175124
}

MSBuildLocator

Lines changed: 0 additions & 1 deletion
This file was deleted.

TMC-CSharp-Runner.sln

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30001.183
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.2.32422.2
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{07DC521B-E707-4814-B2CA-1335B7F00C09}"
77
EndProject
@@ -13,8 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAssembly", "TestAssembly\TestAssembly.csproj", "{A350F515-23AB-4288-8972-800E05261642}"
1515
EndProject
16-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Locator", "MSBuildLocator\src\MSBuildLocator\Microsoft.Build.Locator.csproj", "{342FF612-37EC-41B4-BB5F-CD6A52D5C32E}"
17-
EndProject
1816
Global
1917
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2018
Debug|Any CPU = Debug|Any CPU
@@ -41,10 +39,6 @@ Global
4139
{A350F515-23AB-4288-8972-800E05261642}.Debug|Any CPU.Build.0 = Debug|Any CPU
4240
{A350F515-23AB-4288-8972-800E05261642}.Release|Any CPU.ActiveCfg = Release|Any CPU
4341
{A350F515-23AB-4288-8972-800E05261642}.Release|Any CPU.Build.0 = Release|Any CPU
44-
{342FF612-37EC-41B4-BB5F-CD6A52D5C32E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{342FF612-37EC-41B4-BB5F-CD6A52D5C32E}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{342FF612-37EC-41B4-BB5F-CD6A52D5C32E}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{342FF612-37EC-41B4-BB5F-CD6A52D5C32E}.Release|Any CPU.Build.0 = Release|Any CPU
4842
EndGlobalSection
4943
GlobalSection(SolutionProperties) = preSolution
5044
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)