Galin Iliev's blog

Software Architecture & Development

MSBuild - Debug a msbuild script–enters the debug switch

It would be great if it was possible to debug msbuild script. Step in, step out, see properties and values… Seems like there is a way to do it via VS2010 although unsupported. What needs to be done is:

  1. Ensure you debug “Just my code”:
  2. Enable undocumented "/debug" switch on MSBuild.exe by adding registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\4.0 key to have debuggerenabled=true. Execute this in command prompt:
    reg add HKLM\SOFTWARE\Microsoft\MSBuild\4.0 /v DebuggerEnabled /t REG_SZ /d true
  3. Check /debug switch:
    MSBuild /?
  4. Run your build with /debug switch:
    MSBuild MyCode.proj /debug
  5. Once you get standard JIT debugging prompt make sure you select "Manually choose the debugging engines".
  6. Select Managed mode only:
  7. Enjoy


Thanks to Visual Studio blog and Dan Smile

Also John Robins has a way to do it but I didn’t try it…

VS2010: Cannot change the specified .NET framework version or profile for a test project

I received the error message "attempted re-targeting of the project has been canceled. You cannot change the specified .NET framework version or profile for a test project" when trying to target the .NET 3.5 framework after upgrading to Visual Studio 2010.

And this was tricky – we want to move to VS 2010 but still compile against .NET .3.5. Although having tests target .NET 4 is not critical is not very nice. We don’t want to have bugs slipped out because production code and test code are compiled against different .NET versions.

Luckily there is a solution – manually editing .csproj file and trick VS2010 to think it is not a test class library but simply class library:

  1. Open .csproj file with notepad.
  2. Search for this line:
  3. <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};
  4. Remove {3AC096D0-A1C2-E12C-1390-A8335801FDAB} guid
  5. Save file and Open in VS 2010
  6. It is ready to be re-targeted

Hope this helps

TFS 2010 Basic: Server build of Windows Phone 7 project

I just started taking advantage of TFS 2010 Basic (or TFS 2010 for SourceSafe users as Brian Harry named it Smile) and found something interesting to share. The project I was testing with is Windows Phone 7 one and it was building perfectly form VS 2010. But when triggered a server build the agent fails with following error:

C:\Program Files (x86)\MSBuild\Microsoft\Silverlight for Phone\v4.0\Microsoft.Silverlight.Common.targets (185): The "CompileXaml" task failed unexpectedly. System.IO.FileLoadException: Could not load file or assembly 'PresentationCore, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) File name: 'PresentationCore, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'  Server stack trace:     at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)    at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)    at System.Reflection.Assembly.Load(String assemblyString)    at Microsoft.Silverlight.Build.Tasks.CompileXaml.LoadSilverlightAssemblies(String[] frameworkPaths)    at Microsoft.Silverlight.Build.Tasks.CompileXaml.GenerateCode(ITaskItem item, Boolean isApplication)    at Microsoft.Silverlight.Build.Tasks.CompileXaml.Execute()    at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)  Exception rethrown at [0]:     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    at Microsoft.Build.Framework.ITask.Execute()    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) 

As the name of TFS 2010 Basic suggests I have everything on same machine – VS 2010, TFS server, build controller, build agent… and it still failed.

The solution is in Build definitions: set MSBuild platform to X86:


Seems like Windows Phone 7 projects need to be build using x86 as a target platform only…

Hope this helps

VS 2010: Executing Unit Tests in parallel

This almost slipped out of my sight. Visual Studio 2010 adds an option to execute unit tests in parallel. Probably it would be obvious but let me emphasis that all multithreading issues could arise and let tests fails in such case. So all tests must be thread safe and tested code as well…

The option to enable this is very hidden Smile It is not exposed via VS GUI but in .testsettings file instead. It has to be edited in XML editor and add to <Execution> parallelTestCount attribute greater than 1(e.g. parallelTestCount=”4”)

Hope this helps