无法加载Microsoft.Build或其中一个依赖项

时间:2018-03-13 14:40:02

标签: c# wpf msbuild dependencies assemblies

我在WPF项目中使用Microsoft.Build框架在运行时构建项目。在我的app.config中,我指定了以下程序集:

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Build" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
    <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Build.Utilities.Core" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
    <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Build.Framework" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
    <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Build.Tasks.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Build.Engine" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
  </dependentAssembly>

以下引用位于我的项目文件(.csproj)中:

<Reference Include="Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.Build.15.5.179\lib\net46\Microsoft.Build.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.Build.Framework.15.5.179\lib\net46\Microsoft.Build.Framework.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.Build.Tasks.Core.15.5.179\lib\net46\Microsoft.Build.Tasks.Core.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.Build.Utilities.Core.15.5.179\lib\net46\Microsoft.Build.Utilities.Core.dll</HintPath>
  <Private>True</Private>
</Reference>

Microsoft.Build软件包的NuGet版本为15.5.179。这在运行和调试项目时工作正常。我安装的软件包是:

  • Microsoft.Build
  • Microsoft.Build.Framework
  • Microsoft.Build.Runtime
  • Microsoft.Build.Tasks.Core
  • Microsoft.Build.Utilities.Core

但是,我在我的解决方案中添加了一个安装向导(.vdproj),而检测到的Microsoft.Build。*的依赖关系显示为版本15.1.0.0,当我构建可执行文件时,安装然后运行我的应用程序我得到以下错误:

Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 

我错过了什么..?

更新

有趣的是,已安装的应用程序目录中的MSBuild dll是版本15.5.179 - NuGet版本。

我的项目中的“引用”选项卡包含对版本15.1.0.0的4个引用:

  • Microsoft.Build
  • Microsoft.Build.Framework
  • Microsoft.Build.Tasks.Core
  • Microsoft.Build.Utilities.Core

1 个答案:

答案 0 :(得分:1)

更新Nuget工具安装程序的版本已为我解决。 Microsoft依赖项中似乎存在版本冲突。问题消失了,现在可以成功构建了。

Azure Build Pipeline> NuGet tool installer步骤中,将Version of NuGet.exe to install更改为较新的版本,例如5.4.0。

https://dist.nuget.org/tools.json上查看Nuget的最新ReleasedAndBlessed版本。