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.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"