Adam Lee
Adam Lee

Reputation: 25738

Why Nuget add reference without changing *.csproj file?

I am using Nuget to add some libraries. I found the *.csproj does not change after adding the new library, but the References is actually changed.

Anyone knows how Nuget manage references?

Upvotes: 2

Views: 1986

Answers (2)

John Rasch
John Rasch

Reputation: 63435

While it's true that the NuGet package references are stored in packages.config, NuGet does update the project file to add assembly references. Project file and assembly references are always managed in the project file.

In your case, it's possible that you already had referenced the same assemblies as the NuGet package (so it wouldn't have been modified), or maybe you inspected the version on disk before it was saved.

Upvotes: 2

Steven
Steven

Reputation: 964

Just double-checked. The references are maintaing inside the *.config file. Look at the Image below.

Reference Image

Inside the packages.config file you will see something like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="5.0.0" targetFramework="net40-Client" />
</packages>

And inside the App.config file you will see something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=some-token" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

Note: The values in this example is just a sample value. Your solution may differ.

Upvotes: 2

Related Questions