5

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?

Artem Kachanovskyi
  • 1,839
  • 2
  • 18
  • 27
  • a couple of ideas from [ms](http://msdn.microsoft.com/en-us/library/51ket42z(v=vs.110).aspx). 1) See if the old dll is in the GAC. If so, remove it 2) See if the dll version # is in the app.config, if so, change it. – M Akin Oct 01 '14 at 16:14
  • 1
    Related: [How exactly does the “Specific Version” property of an assembly reference work in Visual Studio?](http://stackoverflow.com/q/24022134/2157640) – Palec Aug 06 '16 at 19:27

1 Answers1

7

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

rsemenov
  • 71
  • 2
  • So if it's better to use the default variant, how to refresh the references automatically via Visual Studio? Or there is nothing to do, but to add/remove references? – Artem Kachanovskyi Oct 02 '14 at 07:14
  • If new version of dll you want to use contains Publisher policy file and registered in GAC then redirection to new assembly will be done automatically. Publisher policy file is provided by dll vendor and define redirection from previous version to new one. If you don't have Publisher policy file you can set assembly redirection in app config or machine config file manually. Look at next refs http://www.c-sharpcorner.com/uploadfile/satisharveti/introduction-to-publisher-policy-file/ and http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx – rsemenov Oct 02 '14 at 09:37