Wednesday, May 25, 2011

Powershell Caching

After having spent some time activating SharePoint features on a test environment using Powershell, and scratching my head wondering why my code doesn't work, I have come to the following conclusion: Powershell is caching me.

What I experienced was things like a feature that could not be activated by powershell. However, when activating that same feature through the Sharepoint user interface, everything went according to plan. Another problem was a resource file that I updated, but where the updates did not show up when I used powershell, only when activating features manually in the browser.

After some experimenting (and screaming) I came to the trembling conclusion:

Powershell is caching my files!

I still don't quite understand how it can do it, but when I activate a feature through powershell session for the first time, the intended assembly is used. If I then update the assembly and try again in the same powershell session, then the original assembly is used again, and my updates are ignored. Now, if powershell used the assembly directly I would just slap my forehead and exclaim "of course!". But as I understand it powershell just tells SharePoint to do something, and SharePoint then does it. How can powershell force SharePoint to use a cached assembly?

Well, the solution is so simple I can't believe it took me so long to find:


When the laughing has subsided, I might update this post to outline what my powershell script does, and how.

No comments:

Post a Comment