我正在构建一个WPF UI,以便在安装时与bootstrapper一起使用。 WPF UI使用Autofac for DI和公共服务定位器。
所有内容都正确编译,但当我尝试访问任何Autofac注册类型时:
public static ILogger Logger => ServiceLocator.Current.GetInstance<ILogger>();
public static IWixViewModel WixViewModel => ServiceLocator.Current.GetInstance<IWixViewModel>();
我得到以下异常:
发生System.IO.FileLoadException HResult = 0x80131040
消息=无法加载文件或程序集&#39; Autofac,Version = 3.5.0.0, Culture = neutral,PublicKeyToken = 17863af14b0044da&#39;或其中一个 依赖。定位程序集的清单定义没有 匹配程序集引用。 (HRESULT的例外情况:0x80131040)
Source = Olbert.Wix.MinimalUI StackTrace:at Olbert.Wix.ViewModels.WixLocator&LT;&GT; c__DisplayClass0_0&LT; .cctor&GT; b__5() 在C:\ Programming \ LanHistory \ WixUI \ viewmodels \ WixLocator.cs:第99行
在Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current()
在Olbert.Wix.ViewModels.WixLocator.get_WixViewModel()中 C:\ Programming \ LanHistory \ WixUI \ viewmodels \ WixLocator.cs:第103行
在Olbert.Wix.WixApp.Run()中 C:\ Programming \ LanHistory \ WixUI \ WixApp.cs:第28行at System.Threading.ThreadHelper.ThreadStart_Context(Object state)at System.Threading.ExecutionContext.RunInternal(执行上下文 executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx)at System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx)at System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback回调,对象状态)at System.Threading.ThreadHelper.ThreadStart()
令我困惑的是,除了Autofac 4.5之外,我在这个解决方案的任何项目中都没有参考。那么为什么要尝试加载v3.5呢? AFAIK,WIX工具集并没有使用Autofac,所以我不认为这是问题的根源。
这是我的bundle.wxs文件:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Bundle Name="LanHistoryBootstrapper"
Version="0.5.0.0"
Manufacturer="Jump for Joy Software"
UpgradeCode="1db721ec-d675-4e60-a55b-d134497a5a35">
<BootstrapperApplicationRef Id="ManagedBootstrapperApplicationHost">
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)Olbert.LanHistorySetupUI.dll"/>
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Autofac.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Autofac.Extras.CommonServiceLocator.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\BootstrapperCore.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\GalaSoft.MvvmLight.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\GalaSoft.MvvmLight.Extras.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\GalaSoft.MvvmLight.Extras.pdb" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\GalaSoft.MvvmLight.pdb" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\GalaSoft.MvvmLight.Platform.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\GalaSoft.MvvmLight.Platform.pdb" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Microsoft.Practices.ServiceLocation.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Microsoft.Practices.ServiceLocation.pdb" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Olbert.j4j.UI.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Olbert.j4j.UI.pdb" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Olbert.Wix.MinimalUI.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Olbert.Wix.MinimalUI.dll.config" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Olbert.Wix.MinimalUI.pdb" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Serilog.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Serilog.Sinks.File.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\Serilog.Sinks.RollingFile.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)\System.Windows.Interactivity.dll" />
<Payload SourceFile="$(var.LanHistorySetupUI.TargetDir)BootstrapperCore.config"/>
</BootstrapperApplicationRef>
<Chain>
<!-- TODO: Define the list of chained packages. -->
<!-- <MsiPackage SourceFile="path\to\your.msi" /> -->
<PackageGroupRef Id="NetFx462Web"/>
<MsiPackage SourceFile="$(var.LanHistorySetup.TargetDir)LanHistorySetup.msi" />
</Chain>
</Bundle>
</Wix>
这是BootstrapperCore.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
<configuration>
<configSections>
<sectionGroup name="wix.bootstrapper" type="Microsoft.Tools.WindowsInstallerXml.Bootstrapper.BootstrapperSectionGroup, BootstrapperCore">
<section name="host" type="Microsoft.Tools.WindowsInstallerXml.Bootstrapper.HostSection, BootstrapperCore" />
</sectionGroup>
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
<wix.bootstrapper>
<!-- Example only. Use only if the startup/supportedRuntime above cannot discern supported frameworks. -->
<!--
<supportedFramework version="v4\Client" />
<supportedFramework version="v3.5" />
<supportedFramework version="v3.0" />
-->
<!-- Example only. Replace the host/@assemblyName attribute with assembly that implements BootstrapperApplication. -->
<host assemblyName="Olbert.LanHistorySetupUI" />
</wix.bootstrapper>
</configuration>
WPF UI组件的app.config文件是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Windows.Interactivity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /></startup></configuration>
答案 0 :(得分:0)
据我记忆,您还必须将程序集绑定重定向添加到BootstrapperCore.config:
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
<configuration>
<configSections>
<sectionGroup name="wix.bootstrapper" type="Microsoft.Tools.WindowsInstallerXml.Bootstrapper.BootstrapperSectionGroup, BootstrapperCore">
<section name="host" type="Microsoft.Tools.WindowsInstallerXml.Bootstrapper.HostSection, BootstrapperCore" />
</sectionGroup>
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Windows.Interactivity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<wix.bootstrapper>
<!-- Example only. Use only if the startup/supportedRuntime above cannot discern supported frameworks. -->
<!--
<supportedFramework version="v4\Client" />
<supportedFramework version="v3.5" />
<supportedFramework version="v3.0" />
-->
<!-- Example only. Replace the host/@assemblyName attribute with assembly that implements BootstrapperApplication. -->
<host assemblyName="Olbert.LanHistorySetupUI" />
</wix.bootstrapper>
</configuration>
如果没有帮助,您可以尝试处理AppDomain.AssemblyResolve
事件以提供正确的程序集。