Skip to content

Commit 0a4aec1

Browse files
committed
Early bind Microsoft.Build.CommandLine.MSBuildApp
1 parent 7a16416 commit 0a4aec1

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Diagnostics;
77
using System.IO;
88
using System.Linq;
9-
using System.Reflection;
109
using System.Runtime.InteropServices;
1110
using System.Text;
1211

@@ -116,18 +115,14 @@ public int ExecuteInProc(string[] arguments)
116115
Environment.SetEnvironmentVariable(kvp.Key, kvp.Value);
117116
}
118117

119-
Assembly assembly = Assembly.LoadFrom(_msbuildPath);
120-
Type type = assembly.GetType(MSBuildAppClassName);
121-
MethodInfo mi = type.GetMethod("Main");
122-
123118
try
124119
{
125-
return (int)mi.Invoke(null, new object[] { arguments });
120+
return Microsoft.Build.CommandLine.MSBuildApp.Main(arguments);
126121
}
127-
catch (TargetInvocationException targetException)
122+
catch (Exception exception)
128123
{
129124
Console.Error.Write("Unhandled exception: ");
130-
Console.Error.WriteLine(targetException.InnerException.ToString());
125+
Console.Error.WriteLine(exception.ToString());
131126

132127
return unchecked((int)0xe0434352); // EXCEPTION_COMPLUS
133128
}

src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.Build.Runtime" Version="$(MicrosoftBuildRuntimePackageVersion)" />
18+
<PackageReference Include="Microsoft.Build.Runtime" Version="$(MicrosoftBuildRuntimePackageVersion)" GeneratePathProperty="true" PrivateAssets="all" />
1919
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelPackageVersion)" />
2020
<PackageReference Include="NuGet.Versioning" Version="$(NuGetVersioningPackageVersion)" />
2121
<PackageReference Include="NuGet.Packaging" Version="$(NuGetPackagingPackageVersion)" />
@@ -28,6 +28,7 @@
2828
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
2929
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCorePackageVersion)" />
3030
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
31+
<Reference Include="$(PkgMicrosoft_Build_Runtime)\contentFiles\any\net5.0\ref\MSBuild.dll" Private="True" />
3132
</ItemGroup>
3233

3334
</Project>

0 commit comments

Comments
 (0)