我试图在WPF (.Net Framework4.0)项目上使用Microsoft.Build程序集执行构建,即不使用VS构建,也不使用命令行中的库存标准MSBuild构建。我的所有项目都成功地构建了,但是WPF项目由于以下消息而失败:
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.WinFx.targets(268,9):error MSB4127:无法从程序集"PresentationBuildTasks、Version=4.0.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35“实例化"MarkupCompilePass1”任务。请验证任务程序集是使用安装在计算机上的Microsoft.Build.Framework程序集的相同版本生成的,并且主机应用程序没有缺少对Microsoft.Build.Framework的绑定重定向。无法将'Microsoft.Build.Tasks.Windows.MarkupCompilePass1‘类型的对象强制转换为“Microsoft.Build.Framework.ITASK”。C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.WinFx.targets(268,9):C:\Service\Test.csproj MSB4060:"MarkupCompilePass1“任务被错误地声明或使用,或者在构造过程中失败。检查任务名称和程序集名称的拼写。
我发现引用(在堆栈溢出上)提到了更新的MSBuild程序集(12.0vs4.0)等等。这些都已经更新了,即来自构建实用程序的引用,但是没有运气。
有什么想法/建议吗?
发布于 2015-12-11 12:53:01
我们正在使用类似的系统,问题似乎来自于页标记的编译:<generator>MSBuild:Compile</generator>。这似乎是以一种吸引4.0框架库的方式调用MSBuild。
对于构建可执行文件,我们只需修改配置,以包括12.0 MSBuild配置所使用的配置。也就是说,将C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe.config中的元素放在您的应用程序配置中。这为我们解决了问题。
发布于 2018-04-25 07:22:34
我找到了解决办法。将绑定重定向到要在App.config中使用的版本
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" 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.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" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>https://stackoverflow.com/questions/32228493
复制相似问题