Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

debugging - 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>

...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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_MACHINESOFTWAREWow6432NodeMicrosoftMSBuild12.0 (64-bit systems) HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuild12.0 (32-bit systems, or if somehow running MSBuild 64-bit)

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...