Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach VS automatically #9939

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,15 +613,33 @@ private static void DebuggerLaunchCheck()
{
#if FEATURE_DEBUG_LAUNCH
case "1":
Debugger.Launch();
break;
{
Debugger.Launch();
break;
}
#endif
case "2":
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press enter to continue...");
Console.ReadLine();
break;
{
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press enter to continue...");
Console.ReadLine();
break;
}

case "3":
{
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
#pragma warning disable CS0436 // Type conflicts with imported type
VisualStudioDebuggerUtility.AttachCurrentProcessToParentVSProcess(enableLog: true);
if (Environment.GetEnvironmentVariable("MSBUILDDEBUGNOBP") != "1")
{
Debugger.Break();
}
#pragma warning restore CS0436 // Type conflicts with imported type
break;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/MSBuildTaskHost/MSBuildTaskHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Link>CopyOnWriteDictionary.cs</Link>
</Compile>
<Compile Include="..\Shared\Constants.cs" />
<Compile Include="..\Shared\Debugging\VisualStudioDebuggerUtility.cs" Link="Debugging\VisualStudioDebuggerUtility.cs" />
<Compile Include="..\Shared\ReadOnlyEmptyDictionary.cs" />
<Compile Include="..\Framework\ErrorUtilities.cs">
<Link>ErrorUtilities.cs</Link>
Expand Down Expand Up @@ -251,4 +252,7 @@
<PackageReference Include="PdbGit" /> -->
<PackageReference Include="LargeAddressAware" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Folder Include="Debugging\" />
</ItemGroup>
</Project>
32 changes: 25 additions & 7 deletions src/MSBuildTaskHost/OutOfProcTaskHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,33 @@ internal static ExitType Execute()
{
#if FEATURE_DEBUG_LAUNCH
case "1":
Debugger.Launch();
break;
{
Debugger.Launch();
break;
}
#endif
case "2":
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press enter to continue...");
Console.ReadLine();
break;
{
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press enter to continue...");
Console.ReadLine();
break;
}
case "3":
{
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
#pragma warning disable CS0436 // Type conflicts with imported type
Shared.Debugging.VisualStudioDebuggerUtility.AttachCurrentProcessToParentVSProcess(enableLog: true);
if (Environment.GetEnvironmentVariable("MSBUILDDEBUGNOBP") != "1")
{
Debugger.Break();
}
Debugger.Break();
#pragma warning restore CS0436 // Type conflicts with imported type
break;
}
}

bool restart = false;
Expand Down
Loading