We have a simple PS script to switch Auto-Start on for WCF services running under AppFabric 1.1:

Import-Module ApplicationServer

Set-ASApplication -SiteName “Default Web Site” -VirtualPath “/x.y.z” -AutoStartMode “All” -EnableApplicationPool

Runs fine, unless you are running it from an MSBuild task:


<Target Name=Setup>

<Exec ContinueOnError=false Command=powershell.exe “$(MSBuildProjectDirectory)\SetupAppFabric.ps1”WorkingDirectory=$(MSBuildProjectDirectory) />

</Target>

, and running MSBuild from the x86 framework on an x64 environment. We get this error:

Set-ASApplication : AppFabric configuration cmdlets require AppFabric Server Worker to be installed on the local machine in order to configure the local WCF and WF services. If you need to administer WCF and WF services locally, install the Worker component and try again. If you need to administer WCF and WF services remotely, use PowerShell remoting features to connect to the remote machine. … + FullyQualifiedErrorId : AppFabricNotInstalled,Microsoft.ApplicationServer.Management.Commands.SetASApplicationCmdlet

The fix is to run MSBuild from the x64 framework (as Callum says), which will run PowerShell from x64 and load up the AppFabric dependencies correctly. But to complicate things, that broke some of our other tasks that required the x86 environment, so we ended up running the build in x86 and shelling out to x64 just for the AppFabric stuff:

<Target Name=Setup>

<!–AppFabric cmdlets need PS2 run in x64 env; other build tasks need x86, so shell out to x64 for this:->

<Exec Command=%SystemDrive%\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe “$(MSBuildProjectDirectory)\Build.proj” /t:SetupAppFabric/>

</Target>

<Target Name=SetupAppFabric>

<Exec ContinueOnError=false Command=’powershell.exe “$(MSBuildProjectDirectory)\SetupAppFabric.ps1″‘WorkingDirectory=$(MSBuildProjectDirectory) />

</Target>

Ugly, but no way around it till our other tasks are x64-compatible.

Oh, and be sure to set your execution policy in the x86 and x64 PowerShell environments if you are running scripts in both.