Skip to content

Commit d568018

Browse files
committed
Exclude MSBuild assemblies from runtime output
Added a `<PackageReference>` for `Microsoft.Build.Framework` (version `17.11.31`) in `Directory.Build.props` with `<ExcludeAssets>` set to `runtime`. This prevents assembly-loading conflicts caused by MSBuild assemblies being copied to the application's `bin` folder, which could lead to errors like `RPC_E_CALL_REJECTED`. Included detailed comments explaining the rationale, runtime behavior, and guidance for maintaining the correct package version.
1 parent 0546461 commit d568018

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Directory.Build.props

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,32 @@
1212
<PackageProjectUrl>https://github.com/ATrefzer/CSharpCodeAnalyst</PackageProjectUrl>
1313
<Title>CSharp Code Analyst</Title>
1414
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<!--
18+
Exclude MSBuild assemblies from runtime output to prevent assembly-loading conflicts.
19+
20+
MSBuild.Locator is used by Microsoft.CodeAnalysis.Workspaces.MSBuild to dynamically
21+
locate and load MSBuild assemblies at runtime from the installed SDK location.
22+
23+
If these assemblies are copied to the application's bin folder (via normal NuGet
24+
package restore), they can conflict with the MSBuild runtime that's already loaded
25+
by the host process, causing RPC_E_CALL_REJECTED errors and other runtime failures.
26+
27+
By setting ExcludeAssets="runtime", we ensure:
28+
- Build-time: Assemblies are available for compilation
29+
- Run-time: Assemblies are loaded dynamically from SDK, not from bin folder
30+
31+
This applies to all projects that transitively depend on Microsoft.Build packages
32+
through the CodeParser project reference.
33+
34+
Note: The version should match what comes transitively from Microsoft.Build.Locator.
35+
To check the current transitive version, run:
36+
dotnet list package (with include-transitive flag)
37+
Update this version when upgrading Microsoft.Build.Locator or related packages.
38+
-->
39+
<PackageReference Include="Microsoft.Build.Framework" Version="17.11.31">
40+
<ExcludeAssets>runtime</ExcludeAssets>
41+
</PackageReference>
42+
</ItemGroup>
1543
</Project>

0 commit comments

Comments
 (0)