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

倾然丶 夕夏残阳落幕 提交于 2019-11-27 18:02:46

问题


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>

...

回答1:


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


来源:https://stackoverflow.com/questions/26079346/how-to-debug-a-project-file-in-msbuild-12-0-vs2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!