MVVM Light 程序集与 Microsoft.Practices.ServiceLocation 冲突

Pau*_*aul 0 mvvm-light

我遇到一个问题,即无法使用 ClickOnce 发布我的 WPF 应用程序。

该应用程序使用 Nuget 包 MVVM Light 4.1.26.1、Unity 2.1.505.2、CommonServiceLocator 1.0。

问题是,当我发布时,一切都构建得很好,但是当我尝试安装 clickonce 包时出现此错误:

无法安装或运行该应用程序。该应用程序要求首先将程序集 Microsoft.Practices.ServiceLocation 版本 1.0.0.0 安装到全局程序集缓存 (GAC) 中。

我做了一些挖掘,发现清单中有两个对该程序集的引用,其中一个被标记为我无法摆脱的先决条件:

<dependency>
    <dependentAssembly dependencyType="preRequisite" allowDelayedBinding="true">
      <assemblyIdentity name="Microsoft.Practices.ServiceLocation" version="1.0.0.0" publicKeyToken="59D6D24383174AC4" language="neutral" processorArchitecture="msil" />
    </dependentAssembly>
  </dependency> 

<dependency>
    <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Microsoft.Practices.ServiceLocation.dll" size="29760">
      <assemblyIdentity name="Microsoft.Practices.ServiceLocation" version="1.0.0.0" publicKeyToken="31BF3856AD364E35" language="neutral" processorArchitecture="msil" />
      <hash>
        <dsig:Transforms>
          <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
        </dsig:Transforms>
        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
        <dsig:DigestValue>eee+a+dQmhpSY/ApLxRipXdEp8UsTaZHXHClBU0Iwyc=</dsig:DigestValue>
      </hash>
    </dependentAssembly>
  </dependency>
Run Code Online (Sandbox Code Playgroud)

我非常确定 ClickOnce 的问题在于该程序集有两个具有相同版本的引用(但请注意不同的公钥标记)。

我创建了一个非常简单的重现,如下所示:

  1. 创建一个新的 WPF 应用程序
  2. 添加Nuget包MVVM Light
  3. 添加Nuget包Unity(还添加名为CommonServiceLocator的依赖包)
  4. 构建并发布 WPF 应用程序
  5. 尝试并安装已发布的 MyApp.application clickOnce 包....收到上面详细说明的错误

这是一个重现项目:

Skydrive 复制项目

有什么想法我可以如何克服这个问题吗?

Jef*_*eff 5

现在是 2019 年,我遇到了类似的问题,发现这个问题作为第一个条目,但发现了另一个(更新的)问题和解决方案,以使 MVVMLight 和 Microsoft.Practices.ServiceLocation 协同工作。

Mvvmlight 5.4.1.1无法与CommonServiceLocator 2.0.4(这都是 2019 年 3 月的最新稳定版本)一起使用,mvvmlight 引导的方式如下ViewModelLocator.cs

有两件事有效:
要么降级到
CommonServiceLocator 1.3.0
Mvvmlight 5.3.0.0

或更改参考

using Microsoft.Practices.ServiceLocation;    
Run Code Online (Sandbox Code Playgroud)

using CommonServiceLocator;
Run Code Online (Sandbox Code Playgroud)