SharePoint 2010 and VS2010: Post-Deployment Scripts

Context

You are developing a SharePoint 2010 application using Visual Studio 2010 on a Windows 2008 64-bit server. You want to run a post-deployment script (PowerShell for example) for debugging:

image

The Problem

When you add a script, for example: powershell $(ProjectDir)\PowerShellScript\MySuperPowerShellScript.ps1

You always get an error when running the script:

Error occurred in deployment step ‘Run Post-Deployment Command’: The command "powershell $(ProjectDir)\PowerShellScript\MySuperPowerShellScript.ps1" exited with error code: 1.

This error is due to the fact that VS2010 runs in 32-bit mode, as well as its post-deployment scripts, and the SharePoint 2010 APIs run in 64-bit mode. This creates errors when executing the script.

[Read More]