Project reference properties - Version number

ぐ巨炮叔叔 提交于 2020-01-05 05:54:27

问题


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:


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>


来源:https://stackoverflow.com/questions/16946613/project-reference-properties-version-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!