Com System.EnterpriseServices和Powershell锁定dll

Com System.EnterpriseServices和Powershell锁定dll,com,powershell,installation,Com,Powershell,Installation,我正在尝试使用System.EnterpriseServices卸载c#com+组件,替换dll并重新安装新版本 问题是,当我到达行复制项时,脚本总是失败,因为System.EnterpriseServices正在锁定目标文件。如果我将脚本分为两部分,一部分调用UnistallAssembly,另一部分执行复制并调用InstallAssembly,那么一切正常 有没有办法强迫system.enterpriseservices发布dll $comRoot = "C:\Comroot\" [void

我正在尝试使用System.EnterpriseServices卸载c#com+组件,替换dll并重新安装新版本

问题是,当我到达行复制项时,脚本总是失败,因为System.EnterpriseServices正在锁定目标文件。如果我将脚本分为两部分,一部分调用UnistallAssembly,另一部分执行复制并调用InstallAssembly,那么一切正常

有没有办法强迫system.enterpriseservices发布dll

$comRoot = "C:\Comroot\"
[void][System.Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices")
[System.String]$applicationName = "My App Name";
[System.String]$typeLibraryName = $null;

$objAdmin = new-object -com COMAdmin.COMAdminCatalog
$objAdmin.ShutdownApplication("$applicationName");
$objAdmin = $null

$helper = New-Object System.EnterpriseServices.RegistrationHelper 
$helper.UninstallAssembly("$comRoot\$StepName.dll", $applicationName)
$helper = $null
$applicationName = $null
[gc]::collect() 
[gc]::WaitForPendingFinalizers()

"SOURCE : $BranchPath\Steps\$StepName\bin\Debug\"
"DESTINATION : $comRoot"
copy-item "$BranchPath\Steps\$StepName\bin\Debug\*$StepName*" -destination "$comRoot" -    force

$helper = New-Object System.EnterpriseServices.RegistrationHelper 
$helper.InstallAssembly("$comRoot\$StepName.dll", [ref] $applicationName, [ref]       $typeLibraryName, [System.EnterpriseServices.InstallationFlags]::ConfigureComponentsOnly);
"Install Complete <$typeLibraryName>"
Read-Host "Press any key to exit"
$comRoot=“C:\comRoot\”
[void][System.Reflection.Assembly]::LoadWithPartialName(“System.EnterpriseServices”)
[System.String]$applicationName=“我的应用程序名”;
[System.String]$typeLibraryName=$null;
$objAdmin=新对象-com-COMAdmin.COMAdminCatalog
$objAdmin.shutdownplication($applicationName”);
$objAdmin=$null
$helper=新对象System.EnterpriseServices.RegistrationHelper
$helper.UninstallAssembly($comRoot\$StepName.dll,$applicationName)
$helper=$null
$applicationName=$null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
“源:$BranchPath\Steps\$StepName\bin\Debug\”
“目标:$comRoot”
复制项目“$BranchPath\Steps\$StepName\bin\Debug\*$StepName*”-目标“$comRoot”-强制
$helper=新对象System.EnterpriseServices.RegistrationHelper
$helper.InstallAssembly($comRoot\$StepName.dll,[ref]$applicationName,[ref]$typeLibraryName,[System.EnterpriseServices.InstallationFlags]::仅配置组件);
“安装完成”
读取主机“按任意键退出”

我想知道是否有可能在您尝试复制时卸载尚未完成?也就是说,对卸载程序集的调用是同步的还是异步的?解决“正在使用的文件”问题的一种方法是尝试使用类似的工具重命名文件,然后安装新版本。

很抱歉延迟回复您。。它将被锁定,直到脚本执行。。如果我打开断点并等待2-3分钟,问题仍然存在。。一旦脚本退出,锁就会消失。我将查看MoveFile.exe。我还发现:它似乎有完全相同的问题