Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

c# - Understanding a csproj assembly reference

I am using VS2010 and I tried to add a few assemblies from local hard disk to my C# project through file reference. Peeking into the csproj file, I found sometimes the file reference appears as

<Reference Include="name">

However sometimes it appears as

<Reference Include="name, Version=xxx, Culture=neutral, 
                                          processorArchitecture=MSIL">

What could cause the difference?


Inspired by k3b's answer, I did another test. I created a new class library project.

  1. Add a file reference. The initial value of Specific Version in Properties pane is False. The csproj file look like

    <Reference Include="Name">
      <HintPath>...</HintPath>
    </Reference>
    
  2. Change Specific Version in Properties pane to True. VS adds version in the Include attribute.

    <Reference Include="Name, Version=...">
      <HintPath>...</HintPath>
    </Reference>
    
  3. Change Specific Version in Properties pane to False again. VS adds a child element SpecificVersion.

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

So it seems that the rule is:

  • When Version is present in Include attribute and there is no SpecificVersion child element, the file assembly is configured to be Specific Version
  • The SpecificVersion child element is only appended with value False.

One thing I still do not understand:

  • For my new test project, if I remove the file reference and add it back again, it goes back to format in point 1, which is the default.
  • For my existing project, if I remove the file reference and add it back again, I get back format in point 3. Although it also means that Specific Version is not used, I am wondering why it does not go back to format in point 1.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  • select the referenced assembly in the project-explorer
  • go to the properties-page

there you find a boolean flag "specific Version"

  • true means: the assembly must have version=xxx
  • false means: ignore the assembly version

(I only have a german-vs2010 so the english translation for the german "Spezifische Version" may be slightly different)

[update]

I tried the following using vcs2010-express german

add reference with default SpecificVersion=False : no version

<Reference Include="Castle.Core">
  <HintPath>......libfluentNHibernateCastle.Core.dll</HintPath>
</Reference>

modified reference: SpecificVersion=True : added version

<Reference Include="Castle.Core, Version=2.5.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
  <HintPath>......libfluentNHibernateCastle.Core.dll</HintPath>
</Reference>

modified reference again: SpecificVersion=False : version remains and new element SpecificVersion

<Reference Include="Castle.Core, Version=2.5.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
  <HintPath>......libfluentNHibernateCastle.Core.dll</HintPath>
  <SpecificVersion>False</SpecificVersion>
</Reference>

It seems that the specific version is remembered but ignorede because of <SpecificVersion>False</SpecificVersion>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...