2

I have a post build step in an msbuild config which executes a powershell script. The powershell script works perfectly if I call it directly from Powershell but fails via msbuild.

It seems it fails after it tries to use classes from the import: Import-Module WebAdministration

I get the error "Error : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error : 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"

I've tried changing the version of powershell loaded by msbuild from 64bit to 32bit but it makes no difference.

Here is the msbuild step:

<Target Name="DevPostBuild">
<PropertyGroup>
  <PowerShellExe Condition=" '$(PowerShellExe)'=='' ">%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
  <ScriptLocation Condition=" '$(ScriptLocation)'=='' ">$(ProjectDir)DevPostBuild.ps1</ScriptLocation>
</PropertyGroup>
<Message Text="$(ScriptLocation)" />
<Exec Condition="Exists($(ScriptLocation))" Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { &amp;'$(ScriptLocation)' } &quot;" />

I'm using VS2010 on a 64bit machine.

Thanks!

smithy
  • 61
  • 5
  • Have you seen this : http://www.techblogistech.com/2012/05/errors-with-powershell-webadministration-module/#more-857 ? – JohnL Aug 21 '13 at 15:16

2 Answers2

0

Visual Studio 2010 is a 32bit process. Powershell will then run as a 32bit process. The WebAdministration module is 64bit only. Try using %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe for PowerShellExe.

Eris
  • 7,378
  • 1
  • 30
  • 45
  • Hi Eris. I've tried using both executables and it seems to run in 32bit mode regardless. However, if you start the same executable as a standalone process it loads as a 64bit process. Is there any way around this?? – smithy Aug 21 '13 at 16:42
  • Possibly http://stackoverflow.com/questions/6514416/wow64-running-powershell-from-within-visual-studio would work? – Eris Aug 21 '13 at 18:53
0

Same in Visual Studio 2017, using syswow64's powershell.exe gives no difference. I had similar challenge while controlling IIS from within MSBuild XML and go same error messages about clases not registered. The Stop-WebAppPool and Stop-Website are useless therefore in MSBuild XML, as all from WebAdministration module, not mentioning Stop-IISSite from IISAdministration module.

In my case I had to utilize old good AppCmd executable from IIS. Works smooth, no issues. I also had the case when application pools and web sites are already stopped so be aware I ignore any error codes.

<Exec Command="$(WinDir)\SysWOW64\inetsrv\appcmd.exe stop apppool /apppool.name:&quot;My Application Pool&quot;" IgnoreExitCode="true" />
<Exec Command="$(WinDir)\SysWOW64\inetsrv\appcmd.exe stop site /site.name:&quot;My Web Site&quot;" IgnoreExitCode="true" />
Dawid Ireno
  • 49
  • 1
  • 6