Make private runtime-only dependencies on .NET Standard 2.0.#11109
Make private runtime-only dependencies on .NET Standard 2.0.#11109JanProvaznik merged 12 commits intodotnet:mainfrom
Conversation
f220ecc to
16f3b06
Compare
The reference to immutable collections is surfaced to `Framework`. This lightens the NS2.0 reference assembly.
16f3b06 to
60122d6
Compare
|
Nice, I've been planning to do something like this (and likely even going further). Will look shortly. |
Let me know how further this can go, happy to do it now or in a subsequent PR. |
|
sorry for letting this be stale for such a long time. The spirit of the change is good, though it breaks CI now (not sure if it ever passed or just accumulated divergence from December). @teo-tsirpanis are you interested in finishing it? |
|
This failure is interesting: Could it be because we inject references to specific versions of maintainenance packages in test projects? |
|
@JanProvaznik CI is now green. Most failures were due to my moving of the The solution is to update |
This reverts commit 60122d6.
434f802 to
0170975
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR modifies three MSBuild project files to mark runtime-only dependencies as private when targeting .NET Standard 2.0, reducing transitive dependencies in reference assemblies. Since #6148 introduced reference-only assemblies for .NET Standard 2.0, many package dependencies are no longer needed at runtime.
- Applied
PrivateAssets="all"to packages not exposed in public APIs for .NET Standard 2.0 targets - Removed explicit package references that are now handled by the private assets pattern
- Validated that dependency chains are simplified (Framework has zero dependencies, Utilities.Core depends only on Framework, Tasks depends only on the previous two)
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Framework/Microsoft.Build.Framework.csproj | Marks System.Collections.Immutable and System.Diagnostics.DiagnosticSource as private assets, removes Microsoft.Win32.Registry reference |
| src/Utilities/Microsoft.Build.Utilities.csproj | Marks multiple dependencies as private assets including StringTools project reference and several System packages, removes System.Text.Encoding.CodePages reference |
| src/Tasks/Microsoft.Build.Tasks.csproj | Consolidates and marks multiple dependencies as private assets, moves some package references from conditional to private assets pattern |
Comments suppressed due to low confidence (1)
src/Utilities/Microsoft.Build.Utilities.csproj:35
- The removal of System.Text.Encoding.CodePages package reference is not replaced with a private assets equivalent in the new ItemGroup below. If this package is still needed for .NET Standard 2.0, it should be included with PrivateAssets="all" in the conditional ItemGroup.
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
rainersigwald
left a comment
There was a problem hiding this comment.
This is fantastic, thank you! Sorry for the delayed merge.
Context
Since #6148 we produce only reference assemblies for .NET Standard 2.0, which means that several of the our NuGet packages' dependencies when targeting .NET Standard 2.0 are unused.
Changes Made
The project files for
Microsoft.Build.Framework,Utilities.CoreandTaskswere updated to applyPrivateAssets="all"to all package references that are not exposed in the package's public API, when targeting .NET Standard 2.0.Testing
I ran
dotnet packon these projects and validated manually that on .NET Standard 2.0,Microsoft.Build.Frameworkhas zero dependencies,Utilities.Coredepends only onFramework, andTasksdepends only on the previous two.Because Roslyn keeps some internal APIs in reference assemblies, these reference assemblies still reference some assemblies whose respective package is not depended upon. I manually validated with ILSpy that the types in these assemblies are used only by internal APIs.
Notes
This is going to be a (minor) source-breaking change if a .NET Standard 2.0 project uses APIs from on one of the removed packages and transitively depended on it. They will have to directly depend on them, and it's not the first time we do a change like this (#9055).
I don't think that this is a binary-breaking change because the .NET Standard 2.0 binaries are not being used at runtime.