2

The passage in question is here - https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#using-packagereference-for-a-project-with-no-packagereferences

And here I quote it:

Using PackageReference for a project with no PackageReferences

Advanced: If you have no packages installed in a project (no PackageReferences in project file and no packages.config file), but want the project to be restored as PackageReference style, you can set a Project property RestoreProjectStyle to PackageReference in your project file.

<PropertyGroup>
    <!--- ... -->
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
    <!--- ... -->
</PropertyGroup>    

This may be useful, if you reference projects which are PackageReference styled (existing csproj or SDK-style projects). This will enable packages that those projects refer to, to be "transitively" referenced by your project.

Can anyone translate it into English? (Russian or Hebrew works too)

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

1

The "PackageReference" feature is more than just adding references to NuGet packages to a single project. It also enables a few features in the build tooling that aren't available to packages.config based projects.

Setting this property for a project that does not (yet) reference any NuGet packages accomplishes two major things:

  1. Enables transitive flow of references: If the project references another project that does reference NuGet packages (via ProjectReference), these packages will be available in the current project and also in projects referencing this project

  2. Using the Nuget Package Manager will only add PackageReference items to the project file. Depending how a Visual Studio instance is configured, it may use packages.config files, PackageReference items or ask you on first package install. By setting this property, you force it to create PackageReference items.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • Something else that may be worth adding is that when a project contains no packages, normally when the first package is added, it uses a Visual Studio setting to either use the default package restore mode, or open a dialog asking the developer to choose. Setting this option will force the project to use PackageReference. – zivkan Dec 07 '18 at 03:05
  • yeah that's what I was trying to say in nr. 2. – Martin Ullrich Dec 07 '18 at 06:57
  • indeed. I read your answer too late at night when I was tired. sorry. – zivkan Dec 07 '18 at 13:39
  • What does it mean **Setting this property for a project** ? I thought `PackageReference` is an item group. Do you mean setting `RestoreProjectStyle = PackageReference` ? – mark Dec 08 '18 at 04:23
  • You seem to understand the domain very well. Would you be so kind to have a look at https://stackoverflow.com/questions/53625112/how-to-pack-the-products-from-multiple-projects-into-one-nuget-without-any-nuspe and https://stackoverflow.com/questions/53674627/how-are-we-supposed-to-execute-package-build-targets-in-the-new-world-where-nuge ? – mark Dec 08 '18 at 04:24
  • yes that property inside the property group is what I mean – Martin Ullrich Dec 08 '18 at 06:28