Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use msbuild in Visual Studio's post build event?

I'm trying to configure the YUICompressor.NET in my Visual Studio project.

As I've understood, I have to create a .proj file and add it to my solution. After that, I need to create a post-build event that will build this .proj file and I'll get my desired output (minified js/css files).

So, I have:

visual studio solution explorer

This .proj contains:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">

  <UsingTask TaskName="CssCompressorTask" AssemblyFile="\..\packages\YUICompressor.NET.MSBuild.2.7.0.0\lib\NET20\Yahoo.Yui.Compressor.Build.MsBuild.dll" />
  <UsingTask TaskName="JavaScriptCompressorTask" AssemblyFile="\..\packages\YUICompressor.NET.MSBuild.2.7.0.0\lib\NET20\Yahoo.Yui.Compressor.Build.MsBuild.dll" />

  <Target Name="Minify">

    <ItemGroup>
      <!-- Single files, listed in order of dependency -->
      <CssFiles Include="Content\*.css"/>
      <JavaScriptFiles Include="Scripts\*.js"/>      
    </ItemGroup>

    <CssCompressorTask
          SourceFiles="@(CssFiles)"
          OutputFile="Content\min.css"
       />

    <JavaScriptCompressorTask
          SourceFiles="@(JavaScriptFiles)"
          OutputFile="Scripts\min.js"
       />

  </Target>
</Project>

I'm trying to build it as the following:

enter image description here

I'm getting the following error:

The command "msbuild C:\Users\Me\Desktop\MvcApplicationExample\MvcApplicationExample\YuiCompressorMsBuild.proj" exited with code 9009.

This error suggests that "msbuild" is not a valid command. So, how should I build this type of project? (I've followed this tutorial: youtube)

Thanks for any help.

like image 222
Ricardo Avatar asked Nov 23 '14 14:11

Ricardo


3 Answers

As you said maybe the visual studio cannot find the MSBuild command, try with the following command instead

"$(MSBuildBinPath)\msbuild.exe"

That uses the complete path to msbuild.

Update (For futures references)

As the comment by Steve Medley, you should not forget the encapsulating quotes.

like image 56
vfabre Avatar answered Oct 22 '22 09:10

vfabre


vfabre is correct to use $(MSBuildBinPath)\msbuild.exe but missing one thing. you should encapsulate that in quotes as there will 99.99% of the time be a space in the file path to msbuild

like image 36
Steve Medley Avatar answered Oct 22 '22 11:10

Steve Medley


Well, one thing that might be a problem is that you want it as a Post-build event but it's set for the Pre-build command line.

like image 23
frasnian Avatar answered Oct 22 '22 11:10

frasnian