PowerShell Does Not Reload Upgraded Assemblies
If you use PowerShell while developing with SharePoint 2010, you may have come across this. After you upgrade your packages, PowerShell uses old versions of the assemblies that were supposed to be upgraded. This is because the assemblies are loaded to PowerShell’s app domain, and as long as they are used from the same app domain, they do not get reloaded. I guess the problem does not exist if you manipulate SharePoint with stsadm, but SharePoint PowerShell Commandlets seem to command SharePoint within the same PowerShell app domain.
The problem has a very simple solution: just close and reopen the PowerShell window. But after you have done that a couple of hundred times, you will probably get… erm… annoyed. I want that every time I invoke my script, it starts in a fresh app domain. That’s why my script starts as follows:
<other script parameters>
Write-Host "Invoking script in a new app domain" -foregroundcolor yellow
powershell.exe -Command $MyInvocation.Line -thisAppDomain
The code starts a new PowerShell process (and a new app domain) with the same arguments as the current invocation, it just adds one extra argument, -thisAppDomain. I know it’s not bullet proof and fails if your script invocation includes piping, for example. Still, it works most of the time and I am not required to reopen the PowerShell window any more to get the dll’s reloaded. If anyone knows a better way to accomplish the “refreshing” of app domain, please share!
Popularity: 3% [?]