【发布时间】:2023-03-14 13:59:01
【问题描述】:
我有一个 powershell 脚本,它依次调用 msbuild.exe 并使用解决方案值和参数参数运行它。如果我通过手动编写该行来运行此脚本,它将按预期运行并构建解决方案,但是,由于此脚本旨在构建多个解决方案,参数、解决方案文件路径和 msbuild 路径都作为变量传递.
我需要运行的行如下所示:
& 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe' FooBar.sln "/t:rebuild" /p:PlatformTarget=AnyCPU /p:Configuration=Release /p:DeployOnBuild=true /p:CustomizablePublishDir=true /p:OutDir=F:\agent\_work\1\s\Deploy.Temp\Foo.Bar.Binaries\\ | Out-Host
而其拆分成变量的方式如下:
$1 = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe'
$2 = 'FooBar.sln'
$3 = "/t:rebuild /p:PlatformTarget=AnyCPU /p:Configuration=Release /p:DeployOnBuild=true /p:CustomizablePublishDir=true /p:OutDir=F:\agent\_work\1\s\Deploy.Temp\Foo.Bar.Binaries\\ | Out-Host"
& $1 $2 $3
对于上下文,为了获得这些值,我们使用一个包含许多节点的 XML,每个节点有 3 个属性。
我运行参数化脚本时遇到的错误如下:
Unhandled Exception: System.ArgumentException: The name "Foo_Bar:PlatformTarget=AnyCPU /p:Configuration=Release /p:DeployOnBuild=true /p:CustomizablePublishDir=true /p:OutDir=F:\agent\_work\1\s\Deploy.Temp\Foo.bar.Binaries\\ | Out-Host" contains
an invalid character ".".
显然这是由于 powershell 处理字符串的方式,但我不知道如何使其工作。
【问题讨论】:
标签: powershell msbuild powershell-5.0