简体   繁体   中英

Project reference properties - Version number

I have a Visual Studio project that references an assembly that I also created. Below is a screen shot of the properties of my assembly reference in the project. When I update my assembly version to 1.1.0.0 , my project fails, and I am thinking this property is the issue.

Since the Version attribute says 1.0.0.0 , does this mean it will always look for my assembly that has a version of 1.0.0.0 ? And incrementing my version to 1.1.0.0 will cause my project to not see the assembly at all?

版本:1.0.0.0

You have 2 versions of strongly named assembly. It is by design behavior for other projects that where compiled against one version of such assembly to fail to load assembly with different version. The reasoning is that version change denotes API change. Otherwise it would be in-place update with the same version - so older code may not be able to function correctly with newer DLL.

Options:

  • If there is no API changes - don't change version of assembly. It means you may deprecate methods, but no add/remove of methods/classes or change in behavior.
  • If you control all projects depending on that assembly - rebuild all with new reference and stop supporting older version (if possible).
  • Provide publisher policy in settings to redirect request for older version to new one. This assumes your new version is really backward compatible with old one.
  • Install all versions in the GAC or just make sure applications get correct version of assembly by putting correct one next to each executable. It is pretty much only approach when you don't control all users of the assembly and there are significant changes in API.

Side note: depending on if the assembly in question is for internal (you control all projects using the assembly) or external consumption you may need to do more work on ensuring backward compatibility and proper deprecation policy.

Publisher policy sample: from article linked above:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
         <assemblyIdentity name="myAssembly"
                           publicKeyToken="32ab4ba45e0a69a1"
                           culture="en-us" />
         <!-- Redirecting to version 2.0.0.0 of the assembly. -->
         <bindingRedirect oldVersion="1.0.0.0"
                          newVersion="2.0.0.0"/>
       </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM