简体   繁体   English

控制台应用程序的引用的C#版本控制

[英]C# versioning of references for a console application

I've built a console application that references version 4.3.2.1 of another dll we've built. 我已经构建了一个控制台应用程序,它引用了我们构建的另一个DLL的版本4.3.2.1。

It worked fine and did its job. 它运作良好并完成了它的工作。

Then version 4.3.2.2 of the dll is built, and the console application starts to die becuase it wants to see 4.3.2.1. 然后构建了DLL的4.3.2.2版本,并且控制台应用程序开始死亡,因为它想要看到4.3.2.1。

Is there any way to tell the console application to use 4.3.2.1 or higher? 有没有办法告诉控制台应用程序使用4.3.2.1或更高版本? The methods that are present in 4.3.2.1 are also present in 4.3.2.2 and will be in all subsequent versions of the dll. 4.3.2.1中存在的方法也存在于4.3.2.2中,并且将存在于dll的所有后续版本中。

Use the <assemblyBinding> element of app.config: 使用app.config的<assemblyBinding>元素:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="Foo.dll"
                              publicKeyToken="1234567890abcdef"
                              culture="neutral" />
            <bindingRedirect oldVersion="4.3.2.1"
                             newVersion="4.3.2.2"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

See also "Redirecting Assembly Versions" for more information. 有关更多信息,另请参阅“重定向程序集版本”

This is assuming you don't want to recompile the app, of course - if you don't mind recompiling, then just setting "Use specific version" to false should be fine. 这假设您不想重新编译应用程序,当然 - 如果您不介意重新编译,那么只需将“使用特定版本”设置为false就可以了。

Pull up the properties window when you have the reference selected to the other DLL. 将引用选择到其他DLL时,请拉出属性窗口。 Make sure the "Specific Version" property is set to false. 确保“特定版本”属性设置为false。

If the dll name changes. 如果dll名称更改。 eg. 例如。 foo-4.3.2.1.dll, foo-4.3.2.2.dll the only way around it is to load the assembly at runtime. foo-4.3.2.1.dll,foo-4.3.2.2.dll唯一的解决方法是在运行时加载程序集。

If the assembly name never changes, its likely that the 'Specific Version' is enabled for your referenced assembly. 如果程序集名称永远不会更改,则可能是为引用的程序集启用了“特定版本”。 Disabling it should fix the problem. 禁用它应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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