views:

460

answers:

2

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  A: 

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.
-->
Si
That looks like it might have worked! Thanks so much. Any idea on why that MarkupCompilePass1 would fail like that though? It just feels a bit like a work-around rather than a fix for me, would be great to get that to compile correctly also. Thanks again for your help!
ChrisHDog
Agree that it is a kludge. Sorry I don't know the answer as to why it is happening, but I'll link your question to my question, so if someone finds out we'll both know :)
Si
I now have the interesting behavior of not working in all cases (i had it working for one wpf application, but now for a second wpf application) ... I've got the ContinueOnError set to true, but the MarkupCompilePass1 still sais FAILD and then then build fails ...
ChrisHDog
Hey again, what's the error?
Si
+1  A: 

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.

James_2195