您可以再次删除 PowerShell 中的添加类型吗? [英] Can you remove an Add-ed Type in PowerShell again?

查看:33
本文介绍了您可以再次删除 PowerShell 中的添加类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用 C# 编写一个库,并在某些情况下使用 PowerShell 对其进行快速测试.但是,这会阻止我重新构建项目,因为 PowerShell 显然仍然打开了 DLL.

I'm currently writing a library in C# and was using PowerShell to quickly test it on some occasions. However, this prevents me from re-building the project as PowerShell obviously still has the DLL open.

Add-Type添加DLL后,有没有办法再次卸载它?文档似乎没有这方面的线索,明显的候选者是 Remove-Type(它不存在 - 无论如何只有一个命令 Type 作为它的名词).每次我想重建时,关闭 PowerShell 并执行所有导航到构建目录并再次添加类型的工作会变得很麻烦.

Is there a way of unloading the DLL again after adding it with Add-Type? The documentation doesn't seem to have clues on that and the obvious candidate would be Remove-Type (which doesn't exist – there is only one command anyway with Type as its noun). It gets cumbersome to close PowerShell and do all the stuff of navigating to the build directory and adding the type again each time I want to rebuild.

推荐答案

正如其他人所说,这是 .NET 行为.无法卸载加载到 AppDomain 中的程序集.只能卸载 AppDomain,powershell 使用单个 appdomain.几年前我在博客上写了一点:

Like the others say, this is a .NET behavior. Assemblies loaded into an AppDomain cannot be unloaded. Only the AppDomain can be unloaded, and powershell uses a single appdomain. I blogged a bit about this some years ago:

https://web.archive.org/web/20170707034334/http://www.nivot.org/blog/post/2007/12/07/WhyAppDomainsAreNotAMagicBullet

当我这样测试时,我通常会保持一个shell打开并使用嵌套shell来进行测试.启动powershell,cd到bin位置然后运行powershell"启动嵌套shell(新进程)退出"重新开始,然后再次运行powershell".

When I test like this, I usually keep a shell open and use a nested shell to do tests. start powershell, cd to bin location then run "powershell" to start nested shell (new process.) "exit" to start over, and run "powershell" again.

这篇关于您可以再次删除 PowerShell 中的添加类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆