2

我将以下功能作为我的 psake 构建的一部分。当构建执行 Candle.exe 时会抛出此错误:

蜡烛.exe : 警告 CNDL1098: 'ext .\Build\Packages\WixWeb\bin\WixIIsExtension.dll' 不是有效的命令行参数。

我认为这是我传递命令行参数的方式的问题,但我终其一生都无法弄清楚。

任何powershell猴子有建议吗?

function buildMsi($build_dir, $template, $directory) { 
    "Building Msi" 
    "Build Folder: $build_dir"
    "Wix Template: $template"
    "Website: $directory"

    $wixXml = [xml](Get-Content $template)
    $namespaceManager = New-Object Xml.XmlNamespaceManager($wixXml.PSBase.NameTable)
    $namespaceManager.AddNamespace("wi", "http://schemas.microsoft.com/wix/2006/wi")
    $components = $wixXml.Wix.Fragment.ComponentGroup

    WalkDirectory $wixXml.PSBase.SelectSingleNode("/wi:Wix/wi:Fragment/wi:DirectoryRef", $namespaceManager) $directory
    $wixXml.Save("$build_dir\WebContent.wxs")

    .\Build\WixWeb\bin\Candle.exe """-dProductName=Foo""`
         ""-dVersion=1.0.0.0""`
         ""-dProductID=0cd64670-5769-4e34-8b21-c6242e7ca5a2""`
         ""-dUpgradeCode=307601e9-4eea-4b5c-938a-354115d5c419""`
         ""-dAppPool=FooAppPool""`
         ""-dInstallDirectory=Foo""`
         ""-dWebAppDirectoryComponentId=CF57E626-1E95-4a89-A0E9-C1AD03C51B12""`
         ""-dIIsAppPoolComponentId=D9138380-19B3-4123-9E22-AB2994B1024B""`
         ""-dIIsWithAppPoolSettingsComponentId=02ca3f08-a1e8-48a3-b4d7-6f5f67c61b96""`
         ""-dIIsWithoutAppPoolSettingsComponentId=d97791b0-f597-46c6-b159-541817527453""`
         ""-ext "".\Build\WixWeb\bin\WixIIsExtension.dll""""`
         ""-ext "".\Build\WixWeb\bin\WixUIExtension.dll""""`
         "".\Build\WixWeb\Shell.wxs""`
         "".\Build\stage\WebContent.wxs"" "

}
4

2 回答 2

2

尝试用单引号替换你的内部双引号,如下所示:

.\Build\WixWeb\bin\Candle.exe " ""-dProductName=Foo"" `
     ""-dVersion=1.0.0.0"" `
     ""-dProductID=0cd64670-5769-4e34-8b21-c6242e7ca5a2"" `
     ""-dUpgradeCode=307601e9-4eea-4b5c-938a-354115d5c419"" `
     ""-dAppPool=FooAppPool"" `
     ""-dInstallDirectory=Foo"" `
     ""-dWebAppDirectoryComponentId=CF57E626-1E95-4a89-A0E9-C1AD03C51B12"" `
     ""-dIIsAppPoolComponentId=D9138380-19B3-4123-9E22-AB2994B1024B"" `
     ""-dIIsWithAppPoolSettingsComponentId=02ca3f08-a1e8-48a3-b4d7-6f5f67c61b96"" `
     ""-dIIsWithoutAppPoolSettingsComponentId=d97791b0-f597-46c6-b159-541817527453"" `
     ""-ext '.\Build\WixWeb\bin\WixIIsExtension.dll'"" `
     ""-ext '.\Build\WixWeb\bin\WixUIExtension.dll'"" `
     "".\Build\WixWeb\Shell.wxs"" `
     "".\Build\stage\WebContent.wxs"" "

此外,如果您使用 `" (反引号后跟双引号)正确转义双引号,您可能会发现它更容易;脚本也可能更健壮。代码示例将变为:

.\Build\WixWeb\bin\Candle.exe " `"-dProductName=Foo`" `
 `"-dVersion=1.0.0.0`" `
 `"-dProductID=0cd64670-5769-4e34-8b21-c6242e7ca5a2`" `
 `"-dUpgradeCode=307601e9-4eea-4b5c-938a-354115d5c419`" `
 `"-dAppPool=FooAppPool`" `
 `"-dInstallDirectory=Foo`" `
 `"-dWebAppDirectoryComponentId=CF57E626-1E95-4a89-A0E9-C1AD03C51B12`" `
 `"-dIIsAppPoolComponentId=D9138380-19B3-4123-9E22-AB2994B1024B`" `
 `"-dIIsWithAppPoolSettingsComponentId=02ca3f08-a1e8-48a3-b4d7-6f5f67c61b96`" `
 `"-dIIsWithoutAppPoolSettingsComponentId=d97791b0-f597-46c6-b159-541817527453`" `
 `"-ext '.\Build\WixWeb\bin\WixIIsExtension.dll'`" `
 `"-ext '.\Build\WixWeb\bin\WixUIExtension.dll'`" `
 `".\Build\WixWeb\Shell.wxs`" `
 `".\Build\stage\WebContent.wxs`" "

不过,YMMV。

于 2009-11-17T22:55:26.730 回答
0

我遇到了类似的问题,最终得到了问题所在。用空格分隔的每个参数也应视为 powershell 命令中的单独参数

如果这是您在 cmd 中编写的原始命令行

.\Build\WixWeb\bin\Candle.exe ^
   -dProductName=Foo ^
   -dVersion=1.0.0.0 ^
   -dProductID=0cd64670-5769-4e34-8b21-c6242e7ca5a2 ^
   -ext .\Build\WixWeb\bin\WixIIsExtension.dll ^
   .\Build\stage\WebContent.wxs

您可以看到参数-dProductName=Foo是一个参数,但是当我们查看-ext .\Build\WixWeb\bin\WixIIsExtension.dll 时,我们可以看到参数名称和值是分开的,因此这些是两个单独的参数,应该作为 2 个字符串而不是单个字符串传递给 candle.exe。-ext 是一个位置参数,它的值应该在参数标记之后。

正确版本:

.\Build\WixWeb\bin\Candle.exe " `"-dProductName=Foo`" `
 `"-dVersion=1.0.0.0`" `
 `"-dProductID=0cd64670-5769-4e34-8b21-c6242e7ca5a2`" `
 `"-ext`" `
 `".\Build\WixWeb\bin\WixIIsExtension.dll'`" `
 `".\Build\stage\WebContent.wxs`" "
于 2020-11-16T21:26:00.590 回答