【发布时间】:2015-09-18 16:35:54
【问题描述】:
我正在使用此代码从 MSBuild 目标调用 PowerShell 脚本:
<PropertyGroup>
<enabler/>
</PropertyGroup>
<Target Name="testTarget">
<CreateItem Include="LogsGeneratorScript.ps1">
<Output ItemName="LogsGenerator" TaskParameter="Include" />
</CreateItem>
<ItemGroup>
<Enabling Include="$(enabler)" />
</ItemGroup>
<PropertyGroup>
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& { &'%(LogsGenerator.Fullpath)' '$(MSBuildProjectName)' '%(Enabling.Identity)'} "
</PowerShellExe>
</PropertyGroup>
<Exec Command="$(PowerShellExe)" />
</Target>
我遇到的问题是 %(Enabling.Identity) 导致 %(LogsGenerator.Fullpath) 被作为空白传递,所以我可以看到当调用 PowerShell 时,整个事情看起来像:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& { &'' 'MyTestProject' 'true'} "
我期待这个:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& { &'LogsGeneratorScript.ps1' 'MyTestProject' 'true'} "
请注意,如果我删除最后一个参数%(Enabling.Identity),那么第一个百分比符号属性将被正确解析:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& { &'LogsGeneratorScript.ps1' 'MyTestProject'} "
有人可以建议一种方法,以便我可以将两个百分比符号参数都传递给 PowerShell 吗?
【问题讨论】:
-
你能告诉我们更多的上下文,包括项目定义吗?我怀疑问题更多在于您如何使用 MSBuild 转换而不是 powershell。
-
@mikez 我已经更新了问题。
标签: powershell msbuild