Anonymous
Anonymous

Reputation: 769

Difference between referencing System by itself and System along with System.Xml.Linq in project.config and csproj files

What's the difference between referencing System in my .csprojfile and referencing System, System.Xml, and System.Xml.Linq?

Some backstory: Using Visual Studio 2017 Community 15.4.4, I decided to upgrade the NuGet packages that my projects were using. Post-upgrade, I noticed that my packages.config and .csproj files now contain "extra" entries. For example, previously my .csproj files contained (among other things) a simple line that stated:

<Reference Include="System" />, 

but now, post upgrade, they also include the lines

<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"/>

Likewise, my project.config files gained entries like:

<package id="System.Xml.Linq"... > 

that previously did exist.

Creating a test solution, I wrote a small function that used a LINQ select statement, printed an enum that lives in System.Xml.Linq, and then manually removed the <Reference Include="System.Xml.Linq"/> in the .csproj file, and everything seemed to compile normally.

So why were these extra entries automatically added? Do they serve a purpose?

Upvotes: 1

Views: 430

Answers (1)

Leo Liu
Leo Liu

Reputation: 76670

why were these extra entries automatically added? Do they serve a purpose?

Not sure why your packages.config files contain "extra" entry <package id="System.Xml.Linq"... >, may be error added or added as dependency for some packages (if you want to dig deeper into the reason for this issue, you should find out why this package added).

Generally, when you create a .NET framework project, the following .NET framework references would be added by default:

<Reference Include="System" />
<Reference Include="System.Xml.Linq"/>

Then you open the package System.Xml.Linq, you will find the this package only include a .NET framework 2.0 lib:

enter image description here

After install this package by nuget, the following lines will add into your project file:

<Reference Include="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Xml.Linq.3.5.21022.801\lib\net20\System.Xml.Linq.dll</HintPath>
  <Private>True</Private>
</Reference>

But if we install this package, above lines will replace the line <Reference Include="System.Xml.Linq"/>. Not sure why it not replace that line.

So that is the reason why you remove the reference to System.Xml.Linq in your .csproj file had no ill effects, Visual Studio still get the dll from the package.

Upvotes: 1

Related Questions