我正在使用以下代码从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吗?