代码之家  ›  专栏  ›  技术社区  ›  Ryan Taylor

从WiX静默执行PowerShell脚本挂起PowerShell

  •  10
  • Ryan Taylor  · 技术社区  · 14 年前

    注意:这个问题也张贴在 WiX Users mailing list .

    PowerShell脚本内容

    # @param website The website under which the module should be compiled and registered.
    # @param name The name of the module to be registered.
    # @param assembly The assembly name, version, culture and public key token to be compiled.
    # @param assemblyType The fully qualified assemebly type to be registered.
    
    param([string]$website = "website", [string]$name = "name", [string]$assembly = "assembly", [string]$assemblyType= "assemblyType")
    
    import-module webadministration
    add-webconfiguration /system.web/compilation/assemblies "IIS:\sites\$website" -Value @{assembly="$assembly"}
    new-webmanagedmodule -Name "$name" -Type "$assemblyType" -PSPath "IIS:\sites\$website"
    

    WiX自定义操作内容:尝试1

    我的第一次尝试是使用&特殊字符来执行脚本。

    <CustomAction Id="RegisterHttpModulePSCmd"
                  Property="RegisterHttpModulePowerShellProperty"
                  Value="&quot;C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe&quot; &amp;'C:\Program Files (x86)\My Company\Scripts\register-httpmodule.ps1' -website 'Default Web Site' -name 'MyCustomModule' -assembly 'MyCompany.Product.Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' -assemblyType 'MyCompany.Product.Feature.MyModule'"
                  Execute="immediate" />
    
    <CustomAction Id="RegisterHttpModulePowerShellProperty"
                  BinaryKey="WixCA" 
                  DllEntry="CAQuietExec64" 
                  Execute="deferred"
                  Return="check" 
                  Impersonate="no" />
    
    <InstallExecuteSequence>
       <Custom Action="RegisterHttpModulePSCmd" After="CostFinalize">NOT  Installed</Custom>
       <Custom Action="RegisterHttpModulePowerShellProperty" After="InstallFiles">NOT Installed</Custom>
    </InstallExecuteSequence>
    

    WiX自定义操作内容:尝试2

    <CustomAction Id="RegisterHttpModulePSCmd"
                  Property="RegisterHttpModulePowerShellProperty"       
                  Value="&quot;C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe&quot; -NoLogo -NonInteractive -NoProfile -File &quot;C:\Program Files (x86)\My Company\Scripts\register-httpmodule.ps1&quot; -website &quot;Default Web Site&quot; -name &quot;MyCustomModule&quot; -assembly &quot;MyCompany.Product.Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx&quot; -assemblyType &quot;MyCompany.Product.Feature.MyModule&quot;"
                  Execute="immediate" />
    
    <CustomAction Id="RegisterHttpModulePowerShellProperty"
                  BinaryKey="WixCA" 
                  DllEntry="CAQuietExec64" 
                  Execute="deferred"
                  Return="check" 
                  Impersonate="no" />
    
    <InstallExecuteSequence>
       <Custom Action="RegisterHttpModulePSCmd" After="CostFinalize">NOT  Installed</Custom>
       <Custom Action="RegisterHttpModulePowerShellProperty" After="InstallFiles">NOT Installed</Custom>
    </InstallExecuteSequence>
    

    这两种方法在对所需的web.config文件进行修改时似乎都起作用,但是,这两种方法都挂起了PowerShell,从而挂起了安装程序。

    附加信息

    MSI (s) (D4:78) [10:26:31:436]: Hello, I'm your 32bit Elevated custom action server.
    CAQuietExec64:  
    CAQuietExec64:  
    CAQuietExec64:  Name             : ConsoleHost
    CAQuietExec64:  Version          : 2.0
    CAQuietExec64:  InstanceId       : 62b0349c-8d16-4bd1-94e5-d1fe54a9ff54
    CAQuietExec64:  UI               : System.Management.Automation.Internal.Host.InternalHostUserI
    CAQuietExec64:                     nterface
    CAQuietExec64:  CurrentCulture   : en-US
    CAQuietExec64:  CurrentUICulture : en-US
    CAQuietExec64:  PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    CAQuietExec64:  IsRunspacePushed : False
    CAQuietExec64:  Runspace         : System.Management.Automation.Runspaces.LocalRunspace
    

    正是在这一点上,安装程序似乎已经停止,因为PosithBar不退出。当我使用任务管理器手动终止PowerShell时,接下来的几条日志消息是:

    CAQuietExec64:  Error 0x80070001: Command line returned an error.
    CAQuietExec64:  Error 0x80070001: CAQuietExec64 Failed CustomAction RegisterHttpModulePowerShellProperty returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) Action ended 10:27:10: InstallFinalize. Return value 3.
    

    如何在不挂起PowerShell的情况下从Wix静默执行PowerShell脚本?

    2 回复  |  直到 9 年前
        1
  •  20
  •   Ben Collins    14 年前

    我在搜索一个不相关的问题时看到了几个这样的帖子,发现 answer 。底线:包括标志 -InputFormat None

        2
  •  0
  •   Sameer Singh    14 年前

    你试过添加关键字吗 exit 剧本的结尾?

    我在一个我一直在做的C项目中遇到了类似的情况。在构建项目之后,我在 <AfterBuild> <Exec> 任务,指定要运行的脚本。如果脚本不包括 关键字VS2010“hangs”-也就是说它实际上在等待PowerShell完成任务,而PowerShell则在等待用户输入。

    如果打开任务管理器或 SysInternals Process Explorer powershell.exe 好像没事似的。如果终止进程,VS2010(即MSBuild)将抛出一个错误。

    所以你需要告诉PowerShell你已经完成了 对它运行的脚本来说,一切都应该会好起来。

    推荐文章