Skip to content

PackageRef project opt-in technique #4488

Open

Description

@clairernovotny

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:

  1. As you can see in the commented out code in Program.cs of Net46ConsoleAppLegacy, I cannot reference the bottom-most class library directly.
  2. 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.

SampleSolution.zip

Activity

  1. clairernovotny commented on Feb 3, 2017

    @clairernovotny
    Author

    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.

  2. davkean commented on Feb 3, 2017

    @davkean

    This user ran into it also: dotnet/sdk#757 (comment)

  3. clairernovotny commented on Feb 3, 2017

    @clairernovotny
    Author

    As another workaround if RestoreProjectStyle goes away is to use the following dummy packageref in the legacy csproj:

    <PackageReference Include="Legacy2CPSWorkaround" Version="1.0.0">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  4. dsplaisted commented on Feb 3, 2017

    @dsplaisted

    What do you mean if RestoreProjectStyle goes away? How would that happen?

  5. rrelyea commented on Feb 3, 2017

    @rrelyea
    Contributor

    It isn't going away for NetCore projects.
    We had to remove reading it for non-cps scenarios for RTM.

  6. dsplaisted commented on Feb 3, 2017

    @dsplaisted

    @rrelyea Will there be a way to force a .NET Framework (non-CPS) project into PackageReference mode without actually adding a PackageReference item?

  7. rrelyea commented on Feb 3, 2017

    @rrelyea
    Contributor

    Another current workaround:
    <PackageReference Update="PlaceholderToConvinceThisProjectToGetTransitivePackageReferenceFromProjectReferences"/>

  8. added this to the milestone on Feb 3, 2017
  9. clairernovotny commented on Feb 3, 2017

    @clairernovotny
    Author

    @rrelyea does that placeholder have to exist? will there be restore errors/failures if it's not there?

  10. rrelyea commented on Feb 3, 2017

    @rrelyea
    Contributor

    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.

  11. clairernovotny commented on Feb 3, 2017

    @clairernovotny
    Author

    Just wasn't sure with Update what happens if it tries to update a package that doesn't exist.

  12. rrelyea commented on Feb 3, 2017

    @rrelyea
    Contributor

    I think both remove and update are ok to do with package names that don't exist.

  13. changed the title [-]NuGet refs are broken with p2p between legacy and netstandard [/-] [+]PackageRef project opt-in technique[/+] on Feb 9, 2017
  14. 62 remaining items

  15. removed this from the Sprint 168 - 2020.03.23 milestone on Apr 13, 2020
  16. nkolev92 commented on Aug 5, 2022

    @nkolev92
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:2Style:PackageReferenceType:Docs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions