最近我想将我的WPF Prism应用程序迁移到7.1,这样我就错过了关于Unity.Abstractions的引用错误。
升级Prism nuget包到Prism7.1,如下面的packages.config中所示:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="2.0.4" targetFramework="net472" />
<package id="Prism.Core" version="7.1.0.431" targetFramework="net472" />
<package id="Prism.Unity" version="7.1.0.431" targetFramework="net472" />
<package id="Prism.Wpf" version="7.1.0.431" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
<package id="Unity.Abstractions" version="4.0.3" targetFramework="net472" />
<package id="Unity.Container" version="5.9.4" targetFramework="net472" />
</packages>
App.xaml代码如下:
<prism:PrismApplication x:Class="WPFPrismDemoApp.App"
x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/">
<Application.Resources>
</Application.Resources>
</prism:PrismApplication>
App.xaml.cs代码如下:
public partial class App : PrismApplication
{
protected override Window CreateShell()
{
return null;
}
protected override void InitializeShell(Window shell)
{
base.InitializeShell(shell);
Application.Current.MainWindow = shell;
var container= Container.GetContainer();
}
当我尝试通过Container.GetContainer访问Unity容器时,我得到以下异常:类型'IUnityContainer'在未引用的程序集中定义。您必须添加对程序集“Unity.Abstractions,Version 3.3.1.0”的引用。我不明白当我将WPF.Unity nuget包升级到最新版本时它会自动将Unity.Abstractions升级到4.0.3.0。
任何人都知道如何通过它。
Unity.Container版本5.8.x包引用Unity.Abstractions版本3.3.1,而较新版本引用版本4.0.3。这打破了Prism中与Bootstrapper的向后兼容性。如果要使用较新的版本,则需要使用新的PrismAplication类。有点难过。
尝试将Unity降级到版本5.8.x.我认为版本5.9.x有一组不同的DLL。