0
我想用System.EnterpriseServices卸載c#com +組件,替換dll並重新安裝新版本。System.EnterpriseServices和Powershell鎖定dll
問題是,當我到達行副本項時,腳本總是失敗,因爲System.EnterpriseSerivces正在鎖定目標文件。如果我將腳本分成兩部分,一部分調用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"
對不起延遲迴到你..它被鎖定,直到腳本執行..如果我把一個斷點,並等待2-3分鐘問題仍然存在..一旦腳本退出鎖定消失。 – Mel 2010-09-16 09:44:21
我來看看MoveFile.exe – Mel 2010-09-16 09:44:41
發現這也是:http://stackoverflow.com/questions/1751006/system-enterpriseservices-registrationhelper-doesnt-release-file它似乎有完全相同的問題 – Mel 2010-09-16 09:46:18