Passing parameters in PowerShell 2.0

不羁的心 提交于 2019-12-12 04:54:45

问题


I have the following test defined in a psake build script:

task package -depends create_wix_content_fragment {

    & $candle -dProductName=Foo `
            -dVersion=$version `
            -dProductID=0cd64670-5769-4e34-8b21-c6242e7ca5a2 `
            -dUpgradeCode=307601e9-4eea-4b5c-938a-354115d5c419 `
            -dAppPool=FooAppPool `
            -dInstallDirectory=Foo `
            -ext WixIISExtension `
            -ext WixUIExtension `
            $wix_shell `
            $build_output_dir\WebContent.wxs
}

For some reason Powershell passes the $version variable as a literal string "$version" instead of the value of "1.0.0.0".

How can I prevent this?


回答1:


Got it, was able to get the correct parameters by modifying the above like this:

task package -depends create_wix_content_fragment {
    $version_parameter = "-dVersion={0}" -f $version

    & $candle -dProductName=Foo `
            $version_parameter `
            -dProductID=0cd64670-5769-4e34-8b21-c6242e7ca5a2 `
            -dUpgradeCode=307601e9-4eea-4b5c-938a-354115d5c419 `
            -dAppPool=FooAppPool `
            -dInstallDirectory=Foo `
            -ext WixIISExtension `
            -ext WixUIExtension `
            $wix_shell `
            $build_output_dir\WebContent.wxs
}


来源:https://stackoverflow.com/questions/1773356/passing-parameters-in-powershell-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!