9

Tracing a project was easy in MSBuild 4.0 / VS2010, all you had to do was set registry key which enabled an msbuild /debug command line option. The debugger would launch and break at the start of the project file.

MSBuild 12 introduces a new environment variable for this. At the command prompt, set MSBUILDDEBUGONSTART=1 and then run MSBuild (no command line switch). This launches the debugger, but does no break. The project just runs to completion with VS open.

Am I missing a setting? Or has this (undocumented) feature been removed? I was able to at least get the debugger to halt by hard coding in a debug break, but this does not help me trace the project file.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         InitialTargets="Init">

  <UsingTask TaskName="LaunchDebugger"
             TaskFactory="Microsoft.Build.Tasks.CodeTaskFactory"
             AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
    <ParameterGroup />
    <Task>
      <Using Namespace="System" />
      <Code Type="Fragment" Language="cs">
        <![CDATA[
          System.Console.WriteLine("Launching debugger...");
          System.Diagnostics.Debugger.Launch();
        ]]>
      </Code>
    </Task>
  </UsingTask>

  <UsingTask TaskName="DebugBreak"
             TaskFactory="Microsoft.Build.Tasks.CodeTaskFactory"
             AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
    <ParameterGroup />
    <Task>
      <Using Namespace="System" />
      <Code Type="Fragment" Language="cs">
        <![CDATA[
          System.Diagnostics.Debugger.Break();
        ]]>
      </Code>
    </Task>
  </UsingTask>

  <Target Name="Init">
    <LaunchDebugger />
    <DebugBreak />
  </Target>

...
SamB
  • 9,039
  • 5
  • 49
  • 56
Paul Williams
  • 3,099
  • 38
  • 34

1 Answers1

5

Add the DebuggerEnabled registry value (with data true) to the following key(s) (the key in the blog post is out of date).

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSBuild\12.0 (64-bit systems) HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\12.0 (32-bit systems, or if somehow running MSBuild 64-bit)

See also:

Community
  • 1
  • 1
weir
  • 4,521
  • 2
  • 29
  • 42