1

I have a power shell script that I want to run with MSBuild. The script itself works and I can pass the path variables in with the command line; however, when I attempt to pass the variables in through MSbuild I get errors in the path.

 <?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;" />

How to I pass the path into MSBuild. The above code errors on /Scripts and /MinifiedJS. Here is the error:

powershell.exe -command "&{.\MinifyCSS.ps1'/Scripts''/MinifiedJS'}" The term '.\MinifyCSS.ps1/Scripts'/MinifiedJS' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:41 + &{.\MinifyCSS.ps1'/Scripts''/MinifiedJS' <<<< } + CategoryInfo : ObjectNotFound: (.\MinifyCSS.ps1/Scripts'/MinifiedJS:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

I also tried place them in quotes and using .\ prior.

Any Suggestions?

1
  • Try replacing the .\ with the actual path to the script. I think the powershell.exe command is creating a new session, that is starting at the default path, not the current path, so .\MinifyCSS.ps1 doesn't exist from the path powershell.exe is starting from. Commented Jan 28, 2013 at 17:48

1 Answer 1

3

Try:

<?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>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.