卸载程序集
Unload assemblies
我正在尝试创建一个脚本来输出 DLL 的完全限定名称列表。我目前使用的脚本在输出我想要的数据时运行良好。
问题是这会锁定文件。因此,如果我想删除我在会话中加载的文件之一,我会收到以下消息:
The action can't be completed because the file is open in Windows PowerShell.
我要更改什么才能让 PowerShell 释放对文件的锁定?
我通常在 Visual Studio 代码中从内部控制台 运行 PowerShell 脚本,但是当我直接从 PowerShell 运行 它时也存在问题。
Enter-PSSession -ComputerName $env:computername
Get-ChildItem -Path $input -Filter '*.dll' | ForEach-Object {
$assembly = [System.Reflection.Assembly]::LoadFrom($_.FullName)
Write-Host $assembly.FullName
}
Exit-PSSession
您可以使用内存中的程序集:
Get-ChildItem -Path $input -Filter '*.dll' | ForEach-Object {
$assembly = [System.Reflection.Assembly]::Load([IO.File]::ReadAllBytes($_.FullName))
Write-Host $assembly.FullName
}
我正在尝试创建一个脚本来输出 DLL 的完全限定名称列表。我目前使用的脚本在输出我想要的数据时运行良好。
问题是这会锁定文件。因此,如果我想删除我在会话中加载的文件之一,我会收到以下消息:
The action can't be completed because the file is open in Windows PowerShell.
我要更改什么才能让 PowerShell 释放对文件的锁定?
我通常在 Visual Studio 代码中从内部控制台 运行 PowerShell 脚本,但是当我直接从 PowerShell 运行 它时也存在问题。
Enter-PSSession -ComputerName $env:computername
Get-ChildItem -Path $input -Filter '*.dll' | ForEach-Object {
$assembly = [System.Reflection.Assembly]::LoadFrom($_.FullName)
Write-Host $assembly.FullName
}
Exit-PSSession
您可以使用内存中的程序集:
Get-ChildItem -Path $input -Filter '*.dll' | ForEach-Object {
$assembly = [System.Reflection.Assembly]::Load([IO.File]::ReadAllBytes($_.FullName))
Write-Host $assembly.FullName
}