简体   繁体   English

.Net程序集映射策略的目的

[英].Net assembly mapping policy purpose

what is the reason/purpose for doing assembly mapping? 进行装配映射的原因/目的是什么? changing version policy?. 更改版本政策?。 I understand that if your app.exe wanted to use a new assembly version you could redirect assembly version, but why would you want to?. 我知道,如果您的app.exe要使用新的程序集版本,则可以重定向程序集版本,但是为什么要这么做? Wouldn't the new version of dependent assembly change? 新版本的从属程序集不会更改吗?

Suppose there is a calc.dll and app.exe. 假设有一个calc.dll和app.exe。 app.exe depends on calc.dll. app.exe取决于calc.dll。 If calc.dll was rebuild and bunch of methods renamed wouldn't app.exe fail when ran when redirected to calc.dll new version? 如果重新生成calc.dll并重命名了许多方法,当将app.exe重定向到calc.dll新版本时,app.exe是否会在运行时失败?

Since authors that care about customers strive to keep interfaces/types of the same assembly backward-compatible then using newer versions of the same assembly is generally not a problem. 由于关心客户的作者努力保持同一个程序集的接口/类型向后兼容,因此使用同一个程序集的较新版本通常不是问题。

Main issue is other assemblies depending on older versions. 主要问题是其他程序集,具体取决于较旧的版本。

Lets say there is common "Shared.dll" which has multiple compatible versions (well known sample - JSON.Net) and used by your code as well by some other DLL your code needs: 可以说有一个常见的“ Shared.dll”,它具有多个兼容版本(众所周知的示例-JSON.Net),并且您的代码以及您的代码需要的某些其他DLL使用它:

ThridParty.dll (v1) -> Shared.dll (v1)
YourApp.exe -> Shared.dll (latest = v5), ThirdParty.dll (v1)

Now you need 2 versions of Shared.dll but both have same file name (solvable by manually loading one) and inability to use objects produces by mixed versions (Shared.Type1 from v1 is not the same as Shared.Type1 from v5 by .Net rules). 现在,您需要2个版本的Shared.dll,但是它们具有相同的文件名(可通过手动加载来解决),并且无法使用混合版本产生的对象(v1中的Shared.Type1与.net中v5的Shared.Type1不同)规则)。

To solve you use assembly redirect and say "whenever anyone asks for Shared.dll v1 use Shared.dll v5". 为解决您的问题,请使用程序集重定向并说“只要有人要求使用Shared.dll v1,请使用Shared.dll v5”。 This way ThridParty.dll continue to work just fine and you no longer face problems with 2 files/versions loaded at the same time. 这样ThridParty.dll可以继续正常工作,并且不再面临同时加载2个文件/版本的问题。

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

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