SharePoint script fails when run as a Visual Studio post-deployment command


I have written a script that inserts some test data into a document library. I intend to use it as a post-deployment step in Visual Studio 2010, so that the library is not empty after a retract & deploy.

The relevant portions of the script are:



It works fine when run as follows from the command line, even immediately after a Visual Studio re-deploy:

However, it does not work when I use the exact same command as a post-deployment command line in the SharePoint project’s properties in Visual Studio:

Interestingly, I can reproduce the error on the command line if I run:

However, the post-deployment command fails even if I explicitly run \windows\System32\WindowsPowerShell\v1.0\powershell and \windows\Syswow64\WindowsPowerShell\v1.0\powershell.

Update: Solution found

I seem to be having a similar problem to the one discussed here:

I cannot access a 64-bit SharePoint API using 32-bit clients. Because Visual Studio is 32-bit, the post-deployment action will run in a 32-bit process and will fail. There is, however, a 64-bit MSBuild. If we let it run the PowerShell script, all is fine.

Wrap the script in an MSBuild file such as this:

Then, set the post-deployment command line to:




It’s important that you use the virtual path of %WINDIR%\SysNative and not the actual
path of C:\Windows\System32. The reason for this is that Visual Studio 2010 is a 32-bit
application that needs to call the 64-bit version of powershell.exe to successfully load the
Microsoft.SharePoint.Powershell snap-in.

(c)”Inside Microsoft SharePoint 2010″, Microsoft Press, Mar 2011


SharePoint script fails when run as a Visual Studio post-deployment command by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply