wpf - Microsoft.Build.BuildEngine.Engine 在构建 WPF 应用程序时抛出错误

标签 wpf msbuild msbuild-buildengine

我正在使用 Microsoft.Build.BuildEngine.Engine 构建 WPF 应用程序。这已成功用于类库和 Web 应用程序,但现在尝试使用它来构建 WPF 应用程序时出现以下错误:

Target MarkupCompilePass1: c:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.WinFX.targets(294,9): error MC1000: Unknown build error, 'API restriction: The assembly 'file:///C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.' Done building target "MarkupCompilePass1" in project "TestWindowsApplication.csproj" -- FAILED.

此应用程序在使用 VisualStudio 2008 构建时构建良好(即从菜单构建),但使用 Microsoft.Build.BuildEngine.Engine 时会抛出此构建错误。有人知道这里发生了什么吗?

最佳答案

我遇到了同样的问题并找到了this在 msdn 上说

By default, markup compilation runs in the same AppDomain as the MSBuild engine. This provides us significant performance gains. This behavior can be toggled with the AlwaysCompileMarkupFilesInSeparateDomain property. The latter one has the advantage of unloading all reference assemblies by unloading the separate AppDomain.

因此,由于抛出的异常表明 PresentationCore 已加载到同一个 AppDomain 中,因此我使用以下方法切换了此属性:

projectToBuild.SetProperty("AlwaysCompileMarkupFilesInSeparateDomain", "True");

这似乎是关键。

希望对您有所帮助。

关于wpf - Microsoft.Build.BuildEngine.Engine 在构建 WPF 应用程序时抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1552092/

相关文章:

c# - 命令执行后调用事件

c# - ListView 在更新时不会改变

c# - 您如何设置单个 TextBox 的样式?

msbuild - 如何设置TeamCity以使用自己的HTTP身份验证的NuGet服务?

c# - 升级到 NetCore 3.1 后找不到版本 (= 2.2.7) 的软件包 Microsoft.NETCore.App.Host.win-x64

wpf - OnApplyTemplate() 如何用于 UserControl?

tfs - 如何从团队构建创建 Web 部署包?

msbuild - 如何使用msbuild替换文件中的字符串?

c# - 在 Microsoft Build Framework 中使用自定义构建任务时出错

c# - Microsoft.Build.Engine 错误(默认目标): Target GetFrameworkPaths: Could not locate the . NET Framework SDK