1

我有一个要与 MSBuild 一起运行的 power shell 脚本。脚本本身可以工作,我可以使用命令行传递路径变量;但是,当我尝试通过 MSbuild 传递变量时,路径中出现错误。

 <?xml version="1.0" encoding="utf-8" ?>
 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="C:\Program Files (x86)\MSBuild\PowershellTask\Powershell.targets"/>

   <Target Name="Minify">
   <PropertyGroup>
       <FilePath>\Scripts</FilePath>
       <OutputPath>\MinifiedJS</OutputPath>
   </PropertyGroup>
   <Exec Command= "powershell.exe -command &quot;&amp;.\MinifyCSS.ps1&apos;$(FilePath)&apos;&apos;$(OutputPath)&apos;}&quot;" />

如何将路径传递到 MSBuild。/Scripts 和 /MinifiedJS 上的上述代码错误。这是错误:

powershell.exe -command "&{.\MinifyCSS.ps1'/Scripts''/MinifiedJS'}" 术语 '.\MinifyCSS.ps1/Scripts'/MinifiedJS' 未被识别为 cmdlet、函数、脚本的名称文件或可运行的程序。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 line:1 char:41 + &{.\MinifyCSS.ps1'/Scripts''/MinifiedJS' <<<< } + CategoryInfo : ObjectNotFound: (.\MinifyCSS.ps1/Scripts'/MinifiedJS:String) [], CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException

我还尝试将它们放在引号中并使用 .\ 之前。

有什么建议么?

4

1 回答 1

3

尝试:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="C:\Program Files (x86)\MSBuild\PowershellTask\Powershell.targets"/>
<Target Name="Minify">
<PropertyGroup>
<FilePath>\Scripts</FilePath>
<OutputPath>\MinifiedJS</OutputPath>
</PropertyGroup>
<Exec Command="powershell.exe .\MinifyCSS.ps1 Scripts MinifiedJS" />
</Target>
</Project>
于 2013-01-28T18:13:47.290 回答