Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a project file in MSBuild 12.0 / VS2013?

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>

...
like image 438
Paul Williams Avatar asked Sep 27 '14 21:09

Paul Williams


1 Answers

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:

  • https://stackoverflow.com/a/27450702/704808
  • https://connect.microsoft.com/VisualStudio/feedback/details/1029251/cannot-debug-msbuild-project-script-file#commentContainer
like image 151
weir Avatar answered Oct 10 '22 05:10

weir