Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# project: how to update referenced assembly version

I have a C# project that references sided assembly. When I try to update the sided assembly, the Version tag stays the same in *.csproj file even if I unload/reload project:

<Reference Include="<myAssembly>, Version=<oldVersion>, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath><myHintPath></HintPath>
</Reference>

So my project tries to reference an old version of assembly, and that causes an exception. It's such a pain to change all those versions in references manually, especially if there are alot of references.

I tried to change some attribute of reference, like SpecificVersion, to True and back to False, and reference refreshed:

<Reference Include="<myAssembly>, Version=<newVersion>, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath><myHintPath></HintPath>
</Reference>

Any ideas, how to automatically update references, if I update an assembly? Note that when I reference any system assembly like System.Configuration.Install, the reference is very simple:

<Reference Include="System.Configuration.Install" />

I can manually remove everything from that reference to sided assembly, but when I change some attribute, it gets back to the complex version, and I'm not sure if that's safe.

So how to update references normally?

like image 412
Artem Kachanovskyi Avatar asked Oct 01 '14 13:10

Artem Kachanovskyi


1 Answers

If you always want to get latest version of assembly from specified path just avoid version attribute in csproj file or set SpecificVersion to False. SpecificVersion is an optional attribute that indicates whether to do the complete name matching (including version, culture and PublicKeyToken).

<Reference Include="assemblyNameOnly">
   <HintPath>pathToDll</HintPath>
</Reference>

But this is not recommended because new version of assembly can cause compilation errors, e.g. method signature is changed. Instead it is better to use strong named assemblies and redirect assembly versions using config files.

<Reference Include="assemblyName, Version=Version, Culture=neutral, PublicKeyToken=keyToken, processorArchitecture=MSIL">
  <SpecificVersion>True</SpecificVersion>
  <HintPath>pathToDll</HintPath>
</Reference>

Then Runtime will locate new assemblies using algorithm described here

like image 120
rsemenov Avatar answered Oct 04 '22 09:10

rsemenov