gpt4 book ai didi

c# - 调试/卸载 PowerShell Cmdlet

转载 作者:行者123 更新时间:2023-11-30 19:55:45 36 4
gpt4 key购买 nike

我正在使用 Visual Studio 2015 在 C# 中编写 PowerShell Cmdlet。调试工作正常,但在关闭 PowerShell 窗口之前我无法重建 DLL。 DLL 似乎正在使用中,因此无法删除(不是在命令行上,也不是使用资源管理器)。我试过删除模块。这成功删除了我的 Cmdlet,但我仍然无法删除/覆盖它。

关闭PowerShell,重建DLL,然后重新打开一个新的PowerShell,cd到DLL路径(通常嵌套很深),再次重新导入,启动命令调试,等等非常不方便调试 session ...

有没有更好的办法卸载DLL?

最佳答案

每当我看到这样的东西时:

It is very unhandy to close the powershell, rebuild the dll and then reopen a new powershell, cd to the dll path (usually deeply nested), re-import it again, start the command to debut, and so on for every single debugging session...

我立即想到,“我应该创建一个脚本来为我完成这些任务”。

有解决办法。您可以启动第二个 PowerShell(如建议的另一个答案)。另一种解决方案是使用脚本为您完成一些工作,最重要的是,您可以将其添加到您的 VS 项目中。

在您的配置文件中创建脚本以启动 PowerShell

function Start-DebugPowerShell
{
PowerShell -NoProfile -NoExit -Command {
function prompt {
$newPrompt = "$pwd.Path [DEBUG]"
Write-Host -NoNewline -ForegroundColor Yellow $newPrompt
return '> '
}
}
}
Set-Alias -Name sdp -Value Start-DebugPowerShell

为您的 Cmdlet 项目编辑调试设置

启动外部程序:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

命令行参数:

-NoProfile -NoExit -Command "Import-Module .\MyCoolCmdlet.dll"

调试您的模块

现在,在 Visual Studio 中,使用 F5 启动调试器,您会看到一个新的 PowerShell 窗口,其中加载了您的 Cmdlet,您可以随心所欲地对其进行调试。

在任何 PowerShell 窗口中使用“sdp”别名

由于 Start-DebugPowerShell 函数在我们的配置文件中并且我们给它起了别名 sdp,您可以随时使用它来启动 PowerShell 的第二个实例。

关于c# - 调试/卸载 PowerShell Cmdlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35917730/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com