2

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

目标 MarkupCompilePass1: c:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.WinFX.targets(294,9): error MC1000: Unknown build error, 'API 限制: 程序集 'file:///C: \Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll' 已从其他位置加载。它不能从同一 appdomain 中的新位置加载。在项目“TestWindowsApplication.csproj”中完成构建目标“MarkupCompilePass1”——失败。

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

4

2 回答 2

3

我有同样的问题,并在 msdn 上找到了这个,上面写着

默认情况下,标记编译在与 MSBuild 引擎相同的 AppDomain 中运行。这为我们提供了显着的性能提升。可以使用 AlwaysCompileMarkupFilesInSeparateDomain 属性切换此行为。后者的优点是通过卸载单独的 AppDomain 来卸载所有引用程序集。

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

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

这似乎是关键。

我希望这有帮助。

于 2009-10-15T04:17:11.390 回答
2

现在这很有趣!看看我上周遇到的这个问题。相同的异常和错误消息,并且与 WPF 有关。

如果您查看引发MarkupCompilePass1异常的 MSBuild 任务的注释,这可能是关于它为什么在 VS2008 中工作但不是来自您的 MSBuild 进程的线索:

<!--
When performing an intellisense compile, we don't want to abort the compile if 
MarkupCompilePass1 fails.  This would prevent the list of files from being handed 
off to the compiler, thereby breaking all intellisense.  For intellisense compiles
we set ContinueOnError to true.  The property defined here is used as the value
for ContinueOnError on the MarkupCompilePass1 task.
-->
于 2009-10-11T23:51:39.113 回答