rasx
rasx

Reputation: 5338

how does visual studio know which assemblies in a NuGet package to reference?

A NuGet package is published with many, many assemblies. Not all assemblies in a NuGet package need to be referenced in the *.csproj in Visual Studio. How does Visual Studio determine which assembly to reference? Is the logic for this in nuget.exe or is it in some NuGet API?

Upvotes: 0

Views: 831

Answers (1)

Leo Liu
Leo Liu

Reputation: 76770

How does Visual Studio determine which assembly to reference? Is the logic for this in nuget.exe or is it in some NuGet API?

This determine should be a combination of nuget.exe and NuGet API in Visual Studio. Visual Studio use NuGet.exe to download the package, then use the NuGet API in Visual Studio to install the corresponding assemblies to the project.

First, NuGet supports putting multiple versions of the same library in a single package when using the convention-based working directory. So we will use different case-sensitive framework names to specifically target multiple frameworks with subfolders under lib:

lib\{framework name}[{version}]

Then we will use NuGet API in Visual Studio to install the package to project, it tries to match the framework name of the assembly with the target framework of the project.

Besides, NuGet Package Manager for Visual Studio is an instance of the combination of nuget.exe and nuget API, so Visual studio knows which assemblies in a NuGet package to reference.

You can refer to the NuGet document Supporting multiple .NET framework versions for more detail info.

Upvotes: 2

Related Questions