Welcome to WindowsClient.net | Sign in | Join

Rob Relyea - XAMLified

WPF, Silverlight and XAML

Why do some WPF projects build differently in VS vs MsBuild?

One of the differences between building in VS and command line is that a WPF build in VS defaults to <AlwaysCompileMarkupFilesInSeparateDomain>true</AlwaysCompileMarkupFilesInSeparateDomain>.

Outside of VS, the default is false.

We're likely changing this to default to True for VS or MsBuild (command line) scenarios for .NET 4 beta2.
If you need to, you could add that property directly to your .csproj or .vbproj.
 

(WPF Forum thread about this.)

 

 

Published Thursday, May 21, 2009 7:54 AM by Rob_Relyea
Filed under: ,

Comments

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Friday, May 22, 2009 7:23 AM

The suggested thread is really helpful. We need more skilled person and people need time to learn things. So after some time - people do better coding.

by Parthiv

# Dew Drop - May 22, 2009 | Alvin Ashcraft's Morning Dew@ Friday, May 22, 2009 8:46 AM

Pingback from  Dew Drop - May 22, 2009 | Alvin Ashcraft's Morning Dew

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Monday, May 25, 2009 12:42 AM

Blend 3 likes to default this to False as well, which causes Resharper to mysteriously crash VS 2008 SP1 (i.e. it just disappears, and when you load VS under WinDbg, you see that it ends up loading 2 different versions of WindowsBase.dll)

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Friday, June 05, 2009 4:37 PM

Mike -

When this value is true, the MarkupCompiler will isolate all assembly loading into a new AppDomain, which will then get thrown out later.

Problems were likely being caused for people because the same assembly was being loaded twice (perhaps 2 different versions of it), and sometimes we would find the wrong one.

Hope that helps.

Thanks, Rob

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Tuesday, February 16, 2010 12:17 PM

Hi,

After many hours of hunting down visual studio crashes i finally reach this single flag as being the cause. (when set to false)

We have a rather complex app with many 3rd party dependencies as well as PostSharp so there were many possible candidates - so this research took some time.

What seems to be happening is this:

When project that includes any 3rd party dependency (for some reason it doesn't happen with any part of the .net framework) There seems to be a kind of temporary memory leak (i know it seems like a contradiction in terms, but i am familiar enough with the behavior of the GC to suspect that something is holding on to references longer then it should).

The symptoms are that on each build or rebuild iteration more memory is being consumed by visual studio until it finally crashes (OutOfMemory).

This seems to depend on the amount of references held by the project (as i mentioned before, we have many, particularly we use 3rd party wpf UI packages).

In my case 3-4 rebuilds within a few minuets would quickly bring a crash.

The reason i am saying it's temporary is because if i leave visual studio alone for a few mins all this memory is released.

Anyhow - You seem to be familiar with this flag (and yours is practically the only coherent hit on google when searching for it)  - do you know why this happens? and why i seem to be the only one to have stumbled upon this?

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Tuesday, February 16, 2010 11:30 PM

AppDomain isolation for each build means that each build creates an appdomain, loads all assemblies needed for XAML compilation in that appdomain, and then unloads the appdomain after the compile.

In .NET we've changed the default value for this...

Sorry you are running into problems.

-Rob

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Wednesday, February 17, 2010 6:33 AM

Hi Rob,

Well - i understand this would mean lots more memory, but what i don't understand is why this memory doesn't get released after the build...?

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Wednesday, February 17, 2010 6:59 AM

When we don't use a seperate AppDomain for Compile, any assemblies we load get loaded in the host appdomain (VS' or Blends' app domain).

The reference DLLs that we load can't be unloaded in that case.

Using AppDomains let's us remove all the reference DLLs from memory, after each compile.

Does that make it clear?

I am correct in thinking that your problem is solved once you turn AppDomain isolation on?

Thanks, Rob

# re: Why do some WPF projects build differently in VS vs MsBuild?@ Monday, February 22, 2010 7:10 AM

Hi,

Yes that does explain it, thanks. I am still kind of curious as to why this problem is not more widespread....but i suppose it may be because most people might be creating the initial project in VS while ours was initially created by our designer (in Blend).

Anyhow - yes, setting the flag to false did solve the problem.

Thanks again.

Yossi.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Page view counter