Project reference properties - Version number

2019-08-07 04:40发布

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?

Version: 1.0.0.0

1条回答
干净又极端
2楼-- · 2019-08-07 04:56

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>
查看更多
登录 后发表回答