我正在尝试创建一个Visual Studio扩展(VS 2022),它可以启动一个程序并附加调试器。此时没有加载任何解决方案/项目。
但是,在启动时会出现一个窗口,提示已经到达断点:
有人知道避免这个断点的方法吗?或者其他API的提示?谢谢。
初始设置:
- 创建VSIX项目
- 添加新项目:命令
这个过程被启动挂起,因为我想添加自己的断点(不是在例子中,但工作)。
~~
static DTE dte;
public static async Task InitializeAsync(AsyncPackage package)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new Command1(package, commandService);
dte = await package.GetServiceAsync(typeof(DTE)) as DTE;
}
public struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public uint dwProcessId;
public uint dwThreadId;
}
public struct STARTUPINFO
{
public uint cb;
public string lpReserved;
public string lpDesktop;
public string lpTitle;
public uint dwX;
public uint dwY;
public uint dwXSize;
public uint dwYSize;
public uint dwXCountChars;
public uint dwYCountChars;
public uint dwFillAttribute;
public uint dwFlags;
public short wShowWindow;
public short cbReserved2;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdError;
}
[DllImport("kernel32.dll")]
public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes,
bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment,
string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
[DllImport("kernel32.dll")]
public static extern uint ResumeThread(IntPtr hThread);
private void Execute(object sender, EventArgs e)
{
STARTUPINFO si = new STARTUPINFO();
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
uint CREATE_SUSPENDED = 0x00000004;
bool success = CreateProcess(@"C:\Windows\System32\notepad.exe", null, IntPtr.Zero, IntPtr.Zero, false, CREATE_SUSPENDED, IntPtr.Zero, null, ref si, out pi);
EnvDTE.Processes processes = dte.Debugger.LocalProcesses;
foreach (EnvDTE.Process proc in processes)
{
if (proc.ProcessID == pi.dwProcessId)
{
proc.Attach();
break;
}
}
ResumeThread(pi.hThread);
}
~~
1条答案
按热度按时间7ivaypg91#
找到解决方案: