Why are C # links added differently between NuGet and Visual Studio

We use NuGet (NuGet Version: 3.5.0.1996) in two different ways. Either we run it from the command line, or we use the NuGet package manager in Visual Studio (2015).

The problem is that these two methods add links to the .csproj file with different formats. If we use the command line, we get a link that looks like this:

<Reference Include="Dummy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> <HintPath>..\packages\Dummy.1.27.10\lib\net452\Dummy.dll</HintPath> <Private>True</Private> </Reference> 

If we use the NuGet package manager in Visual Studio, we get a link that looks like this:

 <Reference Include="Dummy, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\packages\Dummy.1.27.10\lib\net452\Dummy.dll</HintPath> <Private>True</Private> </Reference> 

Note that they add a link with the PublicKeyToken attribute, and the other adds it with the processorArchitecture attribute.

This causes problems with our control source with frequent (and unnecessary) updates and merges.

It would be nice to know why this is happening, but I would rather have a way to prevent it. Any suggestions?

+8
reference c # nuget
source share
1 answer

I did a little research. And decide to post an answer.

PublicKeyToken = null gives you information that the CLR is looking for an unsigned assembly.

  • What is assembly in .net?

Assemblies form the fundamental unit of deployment, version control, reuse, scoping, and security permissions for a .NET-based application. Assemblies take the form of an executable file (.exe) or (in this case) a dynamic link library (.dll) file and are the main blocks of the .NET Framework.

  • What is a public key token?

a public key token is a small number that is a convenient "token" representing a public key. Public keys are quite long; The purpose of the public key token is to allow you to access keys without specifying the entire key. In the same way they say that "Lord of the Rings" is five words, which are a half-million-word novel. It would be inconvenient if every time you wanted to talk about it, you had to indicate these half a million words.

When we know the definitions for assemblers and public key tokens, we can talk about them.

When you add links to your project, they look different.

  • Why? What can make a difference?

Add a link to the file. The "Initial value of a specific version in properties" panels are False. The csproj file looks like

 <Reference Include="Name"> <HintPath>...</HintPath> </Reference> 

Change the specific version in the Properties panel to True. VS adds the version to the Include attribute.

 <Reference Include="Name, Version=..."> <HintPath>...</HintPath> </Reference> 

Change the specific version in the property bar to False again. VS adds a child to SpecificVersion.

 <Reference Include="Name, Version=..."> <HintPath>...</HintPath> <SpecificVersion>False</SpecificVersion> </Reference> 

So, the last definition is as follows:

Which reference type you get depends on how you link the assembly.

Your problems arise from incompatible assemblies. Not from how you refer to them.

-one
source share

All Articles