You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is that transitive refs with PackageRef isn’t working with P2P refs between CPS and Legacy projects. With PackageRefs, this is supposed to be supported.
So build the attached project. Try to run Net46ConsoleAppLegacy.exe. It throws due to a missing Newtonsoft.json. Look at the bin\debug directory and you’ll see that the json ref is missing from the output.
By contrast, look at the Net46ConsoleAppCPS project and you’ll see that things work correctly.
There are a few issues in the legacy project:
As you can see in the commented out code in Program.cs of Net46ConsoleAppLegacy, I cannot reference the bottom-most class library directly.
I also cannot use a transitive NuGet reference there either.
Both of these work from the CPS version. This is very weird behavior to have a difference like this.
I get that P2P transitive refs are “new” for CPS, but transitive NuGet refs are not new and work today in VS 2015 with csproj+json. At the very least, I expect #2 to work and for the correct binaries to be in the output directory even if I cannot use types from ClassLibraryWithPackage in Net46ConsoleAppLegacy. The better scenario is that P2P should fully work here too and the Program.cs code in the CPS and Legacy version of the net46 exe should be the same.
Reacted by Stefan Zander, Evgeniy Mamchenko, Ben Gribaudo, Greg Najda, Florian Ahuis, Jérémy VIGNELLES, Ries Vriend, Bruno Juchli, Michael Dwan, Kent Boogaart and 16 more
This is going to be a very common scenario. People are creating new .NET Standard projects and will add p2p refs to them from their existing "legacy" projects. -- Xamarin, Desktop, etc.
The right binaries won't be in the output directory and people will be confused by this broken behavior.
The only workaround is that you have to add <RestoreProjectStyle>PackageReference</RestoreProjectStyle> to the legacy project.
Reacted by Evgeniy Mamchenko, Florian Ahuis, Bruno Juchli, Stephen Martindale, Ajith Mohan, Tino Hager, Vladimir Ivanov, Todor Mitskovski, Gregory Lyons, junkbondtrader and 1 more
I was just trying to find a workaround that involved a <PackageReference />
When I tried it like above, it said you need include, remove or update.
Your workaround is to use include with a package that is a noop.
You can also do remove or update. I chose update as less confusing than remove, and somewhat self documenting.
RestoreProjectStyle is the recommended way for a project to opt into PackageReference. It is respected for old style csproj projects, and will work correctly as long as the project-system loading the project supports it.
At this point, I don't think there's a product action that needs to be taken.
Let me know if anyone disagrees.
We do need to improve the documentation around this topic.
Activity
clairernovotny commentedon Feb 3, 2017
This is going to be a very common scenario. People are creating new .NET Standard projects and will add p2p refs to them from their existing "legacy" projects. -- Xamarin, Desktop, etc.
The right binaries won't be in the output directory and people will be confused by this broken behavior.
The only workaround is that you have to add
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>to the legacy project.davkean commentedon Feb 3, 2017
This user ran into it also: dotnet/sdk#757 (comment)
clairernovotny commentedon Feb 3, 2017
As another workaround if
RestoreProjectStylegoes away is to use the following dummy packageref in the legacy csproj:dsplaisted commentedon Feb 3, 2017
What do you mean if
RestoreProjectStylegoes away? How would that happen?rrelyea commentedon Feb 3, 2017
It isn't going away for NetCore projects.
We had to remove reading it for non-cps scenarios for RTM.
dsplaisted commentedon Feb 3, 2017
@rrelyea Will there be a way to force a .NET Framework (non-CPS) project into PackageReference mode without actually adding a PackageReference item?
rrelyea commentedon Feb 3, 2017
Another current workaround:
<PackageReference Update="PlaceholderToConvinceThisProjectToGetTransitivePackageReferenceFromProjectReferences"/>clairernovotny commentedon Feb 3, 2017
@rrelyea does that placeholder have to exist? will there be restore errors/failures if it's not there?
rrelyea commentedon Feb 3, 2017
I was just trying to find a workaround that involved a
<PackageReference />When I tried it like above, it said you need include, remove or update.
Your workaround is to use include with a package that is a noop.
You can also do remove or update. I chose update as less confusing than remove, and somewhat self documenting.
Clearly, we want a more elegant solution.
clairernovotny commentedon Feb 3, 2017
Just wasn't sure with Update what happens if it tries to update a package that doesn't exist.
rrelyea commentedon Feb 3, 2017
I think both remove and update are ok to do with package names that don't exist.
[-]NuGet refs are broken with p2p between legacy and netstandard [/-][+]PackageRef project opt-in technique[/+]62 remaining items
Workaround for bug NuGet/Home#4488.
nkolev92 commentedon Aug 5, 2022
RestoreProjectStyleis the recommended way for a project to opt into PackageReference. It is respected for old style csproj projects, and will work correctly as long as the project-system loading the project supports it.At this point, I don't think there's a product action that needs to be taken.
Let me know if anyone disagrees.
We do need to improve the documentation around this topic.