开发者

How can you make a c# project ignore the version number of an assembly?

I am working on a project that references dlls from another product. The product has a release each year and the assemblies version changes for each one, altho开发者_如何转开发ugh the methods stay the same. When I run a build of my project for 2010 when I try and run it for 2009 it throws an error because it is dependent on a different version. Is there a way around this?


If you're referring to a problem at runtime after swapping versions of your assembly without performing a rebuild of the program referencing your newly built assembly, you'll want to use a <bindingRedirect> directive to your program's App.config (or Web.config, if you're talking about a web site.)

bindingRedirect is used to instruct the .NET Framework that it's OK to use a version of an assembly other than the one the application was originally compiled against. By default, the CLR wants to see the same version of a DLL that your application was referencing during build, and if it doesn't it will throw an exception.


Try selecting the reference, and in property window set Specific Version as false.


It is possible to map different .net version of assembly in app.config that you put in application root folder

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Waters.ACQUITY.Remote"
                          publicKeyToken="6c13fd0b3604de03"
                          culture="neutral" />
        <bindingRedirect oldVersion="1.40.0.0"
                         newVersion="1.60.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This is solution when assembly you have referenced has references inside it to another specifc library version.

It happens when at compilation time "Specific version" is set to true. To avoid this problem it should be false.

How can you make a c# project ignore the version number of an assembly?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜