Lan*_*her 11 .net c# versioning dll mef
我有一个使用MEF加载零件的系统.这些部分中的每一部分都依赖于核心库.当我构建项目时,我将这个版本号添加到.dll文件中,如下所示:
此外,还有一个执行MEF组合的应用程序.它还使用核心库.我发现我可以部署"部分"dll,并且组合工作正常,因为应用程序已经加载了部件所依赖的核心库.所以我的文件系统看起来像这样:
我遇到的麻烦是如何处理核心和部件的版本控制.假设我对核心及其中一个部分进行了更新.然后,我部署更改.所以现在我的文件系统可能看起来像:
如何确保part1-v1.dll使用core-v1.dll,part1-v2.dll使用core-v2.dll?我需要加载所有版本的部件并使用适当的核心版本.
零件类看起来像这样:
[Export(typeof(IPart))]
public class Part1
{
public string GetSomethingFromCore()
{
return Core.GetSomethingFromCore();
}
}
[Export(typeof(IPart))]
public class Part2
{
public string GetSomethingFromCore()
{
return Core.GetSomethingFromCore();
}
}
Run Code Online (Sandbox Code Playgroud)
强烈的命名不能解决您的问题吗?如果程序集是针对强命名依赖项构建的,那么您就知道它只接受完全相同的依赖关系到最后一个字节.
或者,如果强命名限制太多,您可以将版本号放在类型名称中.例如:
[Export(typeof(IPart))]
public class Part1v1
{
private readonly ICorev1 core;
[ImportingConstructor]
public Part1v1(ICorev1 core)
{
this.core = core;
}
}
[Export(typeof(IPart))]
public class Part1v2
{
private readonly ICorev2 core;
[ImportingConstructor]
public Part1v2(ICorev2 core)
{
this.core = core;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2900 次 |
| 最近记录: |