Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update dependencies not referenced directly as PackageReference via NuGet?

This question is similar to one described here.

When using "legacy"-style .csproj project files we have a separate packages.config file where all dependencies are listed, including transitive ones. This enables a use case when one installs a package with dependencies and then decides which transitive dependencies can be manually updated. So, the benefits are:

  • Dependencies are easily identifiable due to presence of a flat list
  • Fine-grain control over all dependency versions

E.g., after installing Autofac.WebApi2.Owin from NuGet, we have a picture like this:

Transitive dependencies which are clearly viewable can be manually updated very easily.

When using the new Sdk-style .csproj projects NuGet references are added as <PackageReference/> to the project file itself and transitive dependencies are referenced by MSBuild silently:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Autofac.WebApi2.Owin" Version="4.0.0" />
  </ItemGroup>
</Project>

So, to update transitive dependencies, one would have to

  1. Identify them (e.g. via obj/project.assets.json)
  2. Add all of them explicitly to the project
  3. Perform updates

And this has to be done after each update and for every (!) transitive dependency in the project which is clearly almost impossible.

Possible resolutions:

  • Adding transitive dependencies to the project automatically
  • Show transitive dependency updates in NuGet GUI

Unfortunately, no such feature was found in the documentation.

So, is there an easy way to get the best from two worlds?

like image 877
Andrey Kamyshanov Avatar asked Sep 14 '17 09:09

Andrey Kamyshanov


People also ask

How do I update NuGet dependencies?

Screenshot showing how to upgrade your NuGet packages in JetBrains Rider. Select all the packages you want to update. Click on the Upgrade button to update all selected dependencies. Finally, make sure your application still builds and runs as before.

Does NuGet automatically install dependencies?

By default, when installing NuGet packages, corresponding package dependencies will also be installed in your project. To avoid the installation of dependent packages, choose the Ignore Dependencies option in the Dependency behavior drop-down in NuGet Package Manager.

How do I reference an existing NuGet package from a new project?

NET Core project. After you install a NuGet package, you can then make a reference to it in your code with the using <namespace> statement, where <namespace> is the name of package you're using. After you've made a reference, you can then call the package through its API.


2 Answers

Not possible at the moment but a discussion is open on Github.

like image 134
Andrey Kamyshanov Avatar answered Sep 23 '22 17:09

Andrey Kamyshanov


So, is there an easy way to get the best from two worlds?

I think NuGet already have an easy way to get the best from two worlds.

When using the new Sdk-style .csproj projects, you will notice that there is a tree structure of transitive dependencies in the Reference:

enter image description here

With this structure, we can not only get presence of a flat list can also clearly know the specific dependencies between packages. In the "legacy"-style .csproj, we could to know the flat list, but we could not know the specific dependencies between each package. We need select each package, then check it`s Dependencies. This is very inconvenient.

Besides, we generally do not go over the package itself and update its dependencies directly, this will bring a lot of conflict between dependencies. When you using the new Sdk-style, NuGet hides all dependencies of each package, so that the NuGet Package Manager UI and project file .csproj looks very simple.

If you still want to update one of dependence individually, you can install it, nuget will prompt you, you are update package from version 1 to version 2:like, Autofac:

enter image description here

In this case, you can update dependencies not referenced directly as PackageReference via NuGet.

For more detail info, you can refer to below blog:

https://blog.nuget.org/20170316/NuGet-now-fully-integrated-into-MSBuild.html

like image 30
Leo Liu-MSFT Avatar answered Sep 19 '22 17:09

Leo Liu-MSFT