-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSBuild missing automatic binding redirects when using NuGet transitive pinning #40284
Comments
This might be related: NuGet/Home#10505 |
@jeffkl is this what you would expect from transitive-pinned dependency? It is very surprising to me. |
#2547 is another case of missing binding redirects. |
@AArnott what if you add a top-level dependency with |
@jeffkl No. This top-level reference works just as well at producing the required binding redirect: <PackageReference Include="NuGet.Protocol" PrivateAssets="compile" /> I couldn't tell you why, as I don't know the RAR system that deeply. But I know it's more complicated than just directly referenced assemblies. |
I just fixed another one this morning: |
Just an update, I am actively investigating a fix but am on call this week. I'll let you know when I've made progress on this. |
I think I have fix ready for all of the transitive pinning dependency flow problems: NuGet/NuGet.Client#4953 |
That's great, @jeffkl. Do you think it will resolve my missing binding redirect issue? |
Team triage: closing as a duplicate |
@AR-May It's difficult to understand if the linked item will truly resolve this. In order for binding redirects to be generated, the change would need to impact the inputs to I updated the resolution state to reflect that this was marked as a duplicate of external issue NuGet/NuGet.Client#4953. |
NuGet/Home#12270 is about transitive assets flowing incorrectly through transitive-pinned packages and looks like the canonical issue to me. |
@rainersigwald Thanks for looking. But 12270 appears to be a distinct issue. That one talks about how PrivateAssets should be aggregated when it appears along multiple paths. This issue is about how even a single path with |
Hi @AArnott. Did you find a solution to your problem? We are experiencing the same issue. We use exclude="compile" inside our own NuGet packages to limit the publicly visible API surface to that of the packaged library itself. This is also what Microsoft recommends in the documentation. This leads to PrivateAssets="compile" being added to the PackageReference inside the project file. That in turn leads to the problematic behavior of msbuild that you describe in your initial post: msbuild does not add binding redirects for transitive dependencies. In our case, we have a project that references two NuGet Packages: foo and bar. The package foo has a dependency on a NuGet Package CoreWcf.Primitives with exclude="compile" set. The package bar also has a dependency on CoreWcf.Primitives, but with another version (also with exclude="compile" set). In the project that references both foo and bar, no binding redirects for CoreWcf.Primitives will be generated. This leads to a runtime exception at some point. A workaround, quite ugly, is to reference CoreWcf.Primitives directly from the project. Another workaround is to remove the exclude="compile" from the foo and bar packages. |
No, I haven't spent any more time on this issue. |
Reactivating (I appear to have missed the ping last year). Moving to SDK since I think this is about what happens to the asset between restore (create |
Issue Description
MSBuild doesn't produce binding redirects automatically for indirect nuget dependencies, leading to runtime failure of my code.
Steps to Reproduce
Within VS, run the Microsoft.ServiceHub.Analyzers.Tests (net472) tests.
Expected Behavior
I expect them to pass (as they do at the command line).
Actual Behavior
Most of the tests fail with this error:
Analysis
The
Directory.Packages.props
file forces theNuGet.Protocol
transitive dependency to 6.4.0, where it would naturally be in the 5.x range. Because this is not a direct dependency, and the indirect dependency holdsPrivateAssets="compile"
on it such that it isn't passed to my compiler (or RAR?), msbuild doesn't produce the necessary binding redirect.When I add my own top-level dependency on
NuGet.Protocol
, such that it goes to RAR, the binding redirect is created and the tests pass.I believe MSBuild should be enhanced to be aware of transitive dependencies so that it can produce the necessary binding redirects.
Versions & Configurations
.NET SDK 7.0.101
Dev17.5
The text was updated successfully, but these errors were encountered: