Microsoft.Build.BuildEngine.Engine throws error when building WPF application

4.4k views Asked by At

I am using Microsoft.Build.BuildEngine.Engine to build a WPF application. This has been working successfully for class libraries and web applications, but now trying to use it to build a WPF application I am getting the following error:

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.

This application builds fine when building using VisualStudio 2008 (i.e. build from the menu), but using the Microsoft.Build.BuildEngine.Engine it throws this build error. Anyone know what is going on here?

2

There are 2 answers

0
James_2195 On BEST ANSWER

I had the same problem and found this on msdn which says

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.

So since the exception thrown stated that PresentationCore was loaded in the same AppDomain I switched this property using:

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

Which seemed to be the key.

I hope this helps.

3
si618 On

Now that is interesting! Check out this issue I hit last week. Same exception and error message, and related to WPF.

If you have a look at the comments for the MSBuild MarkupCompilePass1 task throwing the exception, it may be a clue as to why it's working inside VS2008 but not from your MSBuild process:

<!--
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.
-->