Skip to content

Commit 89a9d08

Browse files
YuliiaKovalovaCopilotbaronfel
authored
Update MSBL001 to recommend ExcludeAssets="runtime" and PrivateAssets="all" (#367)
* Revise release steps for MSBuildLocator (#365) * Revise release steps for MSBuildLocator Updated the release process for MSBuildLocator to reflect changes in the pipeline build and release steps. * Remove GitHub release job from pipeline * Fix typo in pipeline build instruction * Update MSBL001 to recommend ExcludeAssets="runtime" and PrivateAssets="all" (#366) * Initial plan * Update MSBL001 diagnostic to suggest both ExcludeAssets="runtime" and PrivateAssets="all" Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
1 parent a42e012 commit 89a9d08

4 files changed

Lines changed: 16 additions & 24 deletions

File tree

Releasing_MSBuildLocator.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ These instructions can only be followed by Microsoft-internal MSBuild maintainer
55
1. Create a PR in https://github.com/microsoft/MSBuildLocator
66
2. Have it reviewed.
77
3. Once approved, merge it.
8-
4. It will automatically start a pipeline build [here](https://dev.azure.com/devdiv/DevDiv/_build?definitionId=11881).
9-
5. Once it succeeds, proceed to [our release page](https://dev.azure.com/devdiv/DevDiv/_release?_a=releases&view=mine&definitionId=408) and create a release (top-right). Specify the build that succeeded.
10-
6. At some point, it will stop to request permission to continue. If you want to publish to NuGet, do so, clicking Approve. It will make a little more progress and push to NuGet! It will then give you the option to "resume" (or cancel) twice. Do so.
11-
8+
4. Start a pipeline build [here](https://dev.azure.com/devdiv/DevDiv/_build?definitionId=11881) for the commited changes.
9+
5. Once it succeeds, proceed to [our release pipeline](https://dev.azure.com/devdiv/DevDiv/_build?definitionId=27492) and queue release. Specify the build that succeeded.
10+
6. On Public NuGet release stage it will stop to request permission to continue. If you want to publish to NuGet, do so, clicking Approve.
11+
1212
### Releasing a non-preview version of MSBuildLocator
1313

1414
The above steps will push a package to NuGet.org, but it is a preview version. To make a final release branded version, merge the latest changes into a release branch like `release/1.5`. Follow the steps as above, and it will publish a release package to NuGet.org.

docs/diagnostics/MSBL001.md

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

33
## Error Message
44

5-
> A PackageReference to the package '{PackageId}' at version '{Version}' is present in this project without ExcludeAssets="runtime" set. This can cause errors at run-time due to MSBuild assembly-loading.
5+
> A PackageReference to the package '{PackageId}' at version '{Version}' is present in this project without ExcludeAssets="runtime" and PrivateAssets="all" set. This can cause errors at run-time due to MSBuild assembly-loading.
66
77
## Cause
88

9-
This error occurs when your project references MSBuild NuGet packages (such as `Microsoft.Build`, `Microsoft.Build.Framework`, `Microsoft.Build.Utilities.Core`, etc.) without excluding their runtime assets. When you use Microsoft.Build.Locator, you want MSBuildLocator to load MSBuild assemblies from an installed Visual Studio or .NET SDK instance, not from the NuGet packages in your output directory.
9+
This error occurs when your project references MSBuild NuGet packages (such as `Microsoft.Build`, `Microsoft.Build.Framework`, `Microsoft.Build.Utilities.Core`, etc.) without excluding their runtime assets and marking them as private. When you use Microsoft.Build.Locator, you want MSBuildLocator to load MSBuild assemblies from an installed Visual Studio or .NET SDK instance, not from the NuGet packages in your output directory.
1010

1111
## Why This Is a Problem
1212

@@ -16,9 +16,11 @@ When MSBuild runtime assemblies are copied to your application's output director
1616
2. **Missing SDKs and build logic**: The MSBuild assemblies in your output directory don't include the SDKs, targets, and build logic needed to build real projects
1717
3. **Inconsistent behavior**: Your application may behave differently than `MSBuild.exe`, `dotnet build`, or Visual Studio when evaluating projects
1818

19+
Additionally, without `PrivateAssets="all"`, downstream projects that reference your project may still get these runtime assets transitively, causing the same issues in consuming projects.
20+
1921
## Example Runtime Error
2022

21-
Without `ExcludeAssets="runtime"`, you may encounter errors like:
23+
Without the proper asset exclusions, you may encounter errors like:
2224

2325
```
2426
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
@@ -34,18 +36,19 @@ This happens because your application loads MSBuild assemblies from your bin fol
3436

3537
## Solution
3638

37-
Add `ExcludeAssets="runtime"` to all MSBuild PackageReferences in your project file:
39+
Add `ExcludeAssets="runtime"` and `PrivateAssets="all"` to all MSBuild PackageReferences in your project file:
3840

3941
```xml
4042
<ItemGroup>
41-
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" />
42-
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="runtime" />
43-
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" />
43+
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" PrivateAssets="all" />
44+
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="runtime" PrivateAssets="all" />
45+
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" PrivateAssets="all" />
4446
...
4547
</ItemGroup>
4648
```
4749

48-
This tells NuGet to use these packages only for compilation, not at runtime. At runtime, MSBuildLocator will load MSBuild assemblies from the registered Visual Studio or .NET SDK installation.
50+
- `ExcludeAssets="runtime"` tells NuGet to use these packages only for compilation, not at runtime. At runtime, MSBuildLocator will load MSBuild assemblies from the registered Visual Studio or .NET SDK installation.
51+
- `PrivateAssets="all"` prevents the package reference metadata from flowing to downstream projects, ensuring that projects referencing your library don't inadvertently get runtime assets from these packages.
4952

5053
## Alternative: Disable the Check (Not Recommended)
5154

release-pipeline.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,3 @@ stages:
7979
https://microsoft.sharepoint.com/teams/toolsforeng/_layouts/OneNote.aspx?id=%2Fteams%2Ftoolsforeng%2FOne%20Note%2FToolsForSoftwareEngineers&wd=target%28Build%20Tools%2FMSBuild%2FGitHub.one%7CFF6DC598-65EC-43D5-AB29-DB38FEB82BC8%2FMyGet%20Feed%7CFAFC6258-899D-48D4-8DB4-892396202C9C%2F%29
8080
onenote:https://microsoft.sharepoint.com/teams/toolsforeng/One%20Note/ToolsForSoftwareEngineers/Build%20Tools/MSBuild/GitHub.one#MyGet%20Feed&section-id={FF6DC598-65EC-43D5-AB29-DB38FEB82BC8}&page-id={FAFC6258-89
8181
onTimeout: 'reject'
82-
83-
- job: GitHubRelease
84-
displayName: 'GitHub release'
85-
dependsOn: PublicNuGetRelease
86-
pool: server
87-
steps:
88-
- task: ManualValidation@0
89-
displayName: 'Create GitHub release'
90-
inputs:
91-
instructions: 'Create the GitHub release manually'
92-
onTimeout: 'reject'

src/MSBuildLocator/build/Microsoft.Build.Locator.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<Error
2020
Condition="@(_DistinctMSBuildPackagesReferencedPoorly->Count()) > 0"
2121
Code="MSBL001"
22-
Text="A PackageReference to the package '%(_DistinctMSBuildPackagesReferencedPoorly.NuGetPackageId)' at version '%(_DistinctMSBuildPackagesReferencedPoorly.NuGetPackageVersion)' is present in this project without ExcludeAssets=&quot;runtime&quot; set. This can cause errors at run-time due to MSBuild assembly-loading."
22+
Text="A PackageReference to the package '%(_DistinctMSBuildPackagesReferencedPoorly.NuGetPackageId)' at version '%(_DistinctMSBuildPackagesReferencedPoorly.NuGetPackageVersion)' is present in this project without ExcludeAssets=&quot;runtime&quot; and PrivateAssets=&quot;all&quot; set. This can cause errors at run-time due to MSBuild assembly-loading."
2323
HelpLink="https://aka.ms/msbuild/locator/diagnostics/MSBL001"
2424
/>
2525
</Target>

0 commit comments

Comments
 (0)