我必须在MSI中创建一个自定义操作,因此我已经在* WXI文件中定义了一个自定义操作,并以此方式进行了操作:
function addOrOverrideStartupNode ($excelVersion) {
$pathDir = $pathDir + $excelVersion + "\"
if (Test-Path -Path $pathDir) {
$filePath = $pathDir + $fileName
if ([System.IO.File]::Exists($filePath)) {
$xmlFrom = [xml] (Get-Content "c:\Git\nova\Components\Installers\resources\EXCEL.EXE.config")
$xmlFromStartupNode = $xmlFrom.configuration.startup
Write-Host "Add property to configuration if it does not exist, override otherwise"
$xmlTo = [xml] (Get-Content $filePath)
$xmlToCurrentStartupNode = $xmlTo.configuration.startup
if ($xmlToCurrentStartupNode) {
$xmlTo.configuration.RemoveChild($xmlToCurrentStartupNode)
}
$xmlTo.SelectSingleNode("configuration").AppendChild($xmlTo.ImportNode($xmlFromStartupNode, $true))
$xmlTo.Save($filePath)
} else {
Write-Host "Copy EXCEL.EXE.config file from CAC build folder to Excel folder"
Copy-Item -Path "c:\Git\nova\Components\Installers\resources\EXCEL.EXE.config" -Destination $pathDir
}
}
}
$excelVersions = @("12", "16")
$pathDir = "C:\Program Files (x86)\Microsoft Office\Office"
$fileName = "EXCEL.EXE.config"
foreach ($excelVersion in $excelVersions) {
Write-Host "Updating EXCEL.EXE.config located in $pathDir$excelVersion"
addOrOverrideStartupNode $excelVersion
}
自定义操作定义:
<!-- CUSTOM ACTIONS -->
<CustomAction Id="SP_PopulateExcelConfig"
Property="POWERSHELLEXE"
ExeCommand=""[POWERSHELLEXE]" -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "[POWERSHELLSCRIPT] ""
Execute="immediate" />
我看到我的Powershell脚本被调用了,但是失败了,提示“字符串缺少终止符:”。 “,但是当我从常规ps1文件中调用此脚本时,它可以正常工作。如何解决?