开发者

System.EnterpriseServices and Powershell Locking dll

I am trying to use System.EnterpriseServices to uninstall a c# com+ component, replace the dll and reinstall the new version.

The problem is that when I get to the line copy-item the script always fails because System.EnterpriseSerivces is locking the destination file. If I break the script up into two sections one that calls UnistallAssembly and a second that does the copy and calls InstallAssembly everything works.

Any ideas for forcing system.enterpriseservices to release dll?

$comRoot = "C:\Comroot\"
[void][System.Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices")
[System开发者_如何学Python.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"


I wonder if it is possible the uninstall isn't finished by the time you attempt the copy? That is, is the call to UninstallAssembly sync or async? One way to work around "file in use" issues is to attempt to rename the file using a tool like the SysInternals MoveFile.exe and then install the new version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜