Make the MSBuild runtime assembly check more correct#360
Merged
YuliiaKovalova merged 3 commits intomainfrom Nov 18, 2025
Merged
Make the MSBuild runtime assembly check more correct#360YuliiaKovalova merged 3 commits intomainfrom
YuliiaKovalova merged 3 commits intomainfrom
Conversation
baronfel
commented
Nov 14, 2025
| @@ -1,25 +1,24 @@ | |||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <Target Name="EnsureMSBuildAssembliesNotCopied" AfterTargets="Build" Condition="'$(DisableMSBuildAssemblyCopyCheck)' != 'true'"> | |||
| <Target Name="EnsureMSBuildAssembliesNotCopied" AfterTargets="ResolvePackageAssets" Condition="'$(DisableMSBuildAssemblyCopyCheck)' != 'true'"> | |||
Member
Author
There was a problem hiding this comment.
ResolvePackageAssets creates RuntimeCopyLocalItems for all dependencies, so we have to filter those down to just the ones that came from the MSbuild-related dependencies we want to flag.
baronfel
commented
Nov 14, 2025
| <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Engine'))" /> | ||
| <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.NET.StringTools'))" /> | ||
| <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'NuGet.Frameworks'))" /> | ||
| <MSBuildAssembliesCopyLocalItems Include="@(_MSBuildAssembliesCopyLocalItems->WithMetadataValue('CopyLocal', 'true')->WithMetadataValue('AssetType', 'runtime'))" /> |
Member
Author
There was a problem hiding this comment.
Once we have the candidate set, we can find just the ones that are runtime assets and were copylocal'd.
baronfel
commented
Nov 14, 2025
| <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.NET.StringTools'))" /> | ||
| <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'NuGet.Frameworks'))" /> | ||
| <MSBuildAssembliesCopyLocalItems Include="@(_MSBuildAssembliesCopyLocalItems->WithMetadataValue('CopyLocal', 'true')->WithMetadataValue('AssetType', 'runtime'))" /> | ||
| <_DistinctMSBuildPackagesReferencedPoorly Include="@(MSBuildAssembliesCopyLocalItems->Metadata('NuGetPackageId')->Distinct())" /> |
Member
Author
There was a problem hiding this comment.
such assets will have the nuget package id and version metadata on them, so we can distinct the IDs easily and make nice error messages.
baronfel
commented
Nov 14, 2025
…code + link to enable searching
YuliiaKovalova
approved these changes
Nov 18, 2025
rainersigwald
approved these changes
Nov 18, 2025
This was referenced Nov 19, 2025
Closed
This was referenced Nov 26, 2025
This was referenced Dec 29, 2025
This was referenced Jan 5, 2026
This was referenced Jan 14, 2026
This was referenced Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While debugging test failures in CommunityToolkit/Aspire#949 with @aaronpowell we discovered that the Microsoft.SqlServer.DacFx package includes a dependency on Microsoft.Build that seems to be causing MSbuild runtime dlls to end up in the test project!
This is very likely an authoring error that we should track down with them, but what surprised me was that the check for the RuntimeAssets=exclude provided by this library didn't flag this. On further investigation I discovered two gaps in the check:
The Aspire scenario is
To fix this, we need to do two things
buildTransitivecheckGiven this lib (
dotnet new classlib):and this test project referencing the lib (
dotnet new mstest):Building the
testproject does now trigger our error:While in here, I also added a small README for the package so that the NuGet.org experience is nicer.