views:

15

answers:

1

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"
A: 

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.

Keith Hill
sorry for delay getting back to you.. It it is locked until the script executes.. If I put a breakpoint on and wait for 2-3 mins the problem still exists.. As soon as script exits lock is gone.
Mel
I'll have a look at MoveFile.exe
Mel
Found this also: http://stackoverflow.com/questions/1751006/system-enterpriseservices-registrationhelper-doesnt-release-file it seems to have the exact same problem
Mel