WiX Toolset 6中PowerShell脚本执行失败求助,拟改用C#自定义动作
问题求助
更新说明
重要提示:请勿使用PowerShell,需改用基于.NET4.7.2(非.NET8)的C# DLL自定义动作,其他方案均无效。
场景描述
我已使用WiX Toolset 6创建Product.wxs,用于部署所有必要文件,其中包含一个已验证的PowerShell脚本(AppPoolAndPermissions.ps1)——该脚本需以管理员权限运行,用于将目标应用池的ManagedRuntimeVersion设置为‘No Managed Code’。我将此脚本配置为InstallFiles步骤之后的高权限自定义动作。
已确认该脚本已发布至预期目录,且在管理员PowerShell窗口中运行可完成以下操作:
- 导入WebAdministration模块
- 停止指定应用池
- 修改managedRuntimeVersion为空值(对应‘No Managed Code’)
- 等待5秒
- 重启应用池
为调试添加了Return="ignore"属性,但脚本未执行(无日志生成),已参考相关方案仍未解决。
待解决问题
- 脚本未执行的原因
- 脚本在InstallExecuteSequence中的执行时机是否合理
- ExeCommand配置是否正确
附Product.wxs代码
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui" xmlns:iis="http://wixtoolset.org/schemas/v4/wxs/iis" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"> <?include Config.wxi ?> <Package Id="<projectID>" Name="<company product name> API Installer $(var.Console) v$(var.MajorVersion)" Manufacturer="<company name>" Language="1033" Version="1.0.0" InstallerVersion="500" Compressed="true" UpgradeCode="68C232F3-7CC6-412A-9FAF-9552EBEA6DBF"> <MediaTemplate EmbedCab="true" /> <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is installed." /> <!-- find powershell --> <Property Id="POWERSHELLEXE" Secure="yes"> <RegistrySearch Id="POWERSHELLEXE" Type="raw" Root="HKLM" Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" Name="Path" /> </Property> [..more configurations ..] <CustomAction Id="RunPowerShellScript" Execute="deferred" FileRef="AppPoolScript" Impersonate="no" ExeCommand=""[POWERSHELLEXE]" -NoProfile -ExecutionPolicy RemoteSigned -Command "Start-Process "[POWERSHELLEXE]" -ArgumentList '-NoProfile -ExecutionPolicy RemoteSigned -File "C:\inetpub\wwwroot\Spok\IntegrationApi-SmartSuite-v1\AppPoolAndPermissions.ps1" -AppPoolName "Spok Integration API SmartSuite v1"' -Verb RunAs -Wait" Return="ignore" /> <InstallExecuteSequence> <Custom Action="CheckIIS" After="AppSearch" Condition="NOT IISINSTALLED" /> <Custom Action="RunPowerShellScript" After="InstallFiles" Condition="NOT REMOVE" /> </InstallExecuteSequence> <!-- Directory structure --> <StandardDirectory Id="TARGETDIR"> <Directory Id="WWWROOTDIR" Name="."> <Directory Id="CompanyDir" Name="<companyName>"> <Directory Id="INSTALLFOLDER" Name="IntegrationApi-$(var.Console)-v$(var.MajorVersion)"> [.. more directories ..] </Directory> </Directory> </StandardDirectory> <DirectoryRef Id="INSTALLFOLDER"> <Component Id="MainExecutable" Guid="2655D3B1-9330-4A43-AEFE-75D93621C646"> <File Id="LicenseFile" Source="license.txt" KeyPath="yes" /> <File Id="AppPoolScript" Source="AppPoolAndPermissions.ps1" /> </Component> [.. more files..] </DirectoryRef> <Feature Id="MainFeature" Title="<product name> API $(var.Console) v$(var.MajorVersion)" Level="1"> <ComponentRef Id="MainExecutable" /> [..more components..] </Feature> </Package> </Wix>
内容的提问来源于stack exchange,提问作者Hans Wright
相关产品推荐
相关产品推荐

