'NuGet, Packages.config, .csproj and references
I have a question so that I can better understand NuGet
packages, packages.config
and the .csproj
file.
It is my understanding that the setting in the NuGet Package Manager >> General for default package management format determines if your project uses packages.config
or the .csproj
file for resolving and restoring packages.
In my project we have selected Packages.config.
No problem it compiles and runs. So I decided to test if it would run without the reference for a dll
in the .csproj
file, as it is my understanding it does not use or need this. This is an incorrect assumption as though the package is in the packages.config
file, when I removed the reference in the .csproj
file there was an error in my project and the project would not compile.
I also noticed that if the dll
is not in the references in the Solution Explorer
that it fails to compile as well I( I assume these are the .csproj
references).
So I am not clear on the role of the .csproj
file for a Packages.config
Management format for NuGet
packages and the references in Solution Explorer
.
Solution 1:[1]
The difference is on how you manage your NuGet references.
Before VS2017 the information what NuGet packages to be used during assembly was stored in files packages.config.
Since VS2017 there is a new option called package references which stores this information in the project (.csproj) file.
https://devblogs.microsoft.com/nuget/migrate-packages-config-to-package-reference/
Solution 2:[2]
Before VS2017 and .NET Core, NuGet was not deeply integrated into MSBuild so it needed a separate mechanism to list dependencies in a project: packages.config
or project.json
Using Visual Studio, developer manually integrates MSBuild with NuGet using .csproj
references to the restored packages in a solution-wide folder managed by NuGet.
Starting with VS2017 and .NET Core, NuGet becomes a first class citizen in MSBuild. NuGet package dependencies are now listed as PackageReference in .csproj
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MerlinC |
Solution 2 | Juanon |