应用背景:
一些PowserShell Scripts需要在64 bits windows powershell中执行,例如一些SharePoint 2010的操作。Google在stackoverflow中查到方法,成功运用
Because of file system virtualization, you can't really specify the path to the 64-bit version of PowerShell from a 32-bit process (ie Visual Studio - which hosts the msbuild engine). One hack-ish way to work around this is to create a 64-bit launcher that runs as 64-bit and will launch the 64-bit version of PowerShell. Here's a simple C# program that will do this:
using System;
using System.Diagnostics;
class App
{
static int Main(string[] args)
{
Process process = Process.Start("PowerShell.exe", String.Join(" ", args));
process.WaitForExit();
return process.ExitCode;
}
}
Be sure to compile this as 64-bit like so:
csc .\PowerShell64.cs /platform:x64
Then, from your post-build event execute this launcher exe passing it the parameters you want to invoke 64-bit PowerShell with. Also, with PowerShell 2.0 I would recommend using the File
parameter to execute a script e.g.:
c:\path\PowerShell64.exe -File "$(MSBuildProjectDirectory)\CreateSite.ps1" auto
That said, surely there has to be some other way (utility) that launches exes from a 64-bit process.