How do I use msbuild in Visual Studio's post build event?
Solution 1
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.
Solution 2
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
Solution 3
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.
Ricardo
Updated on June 05, 2022Comments
-
Ricardo about 2 years
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:
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:
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.
-
Ricardo over 9 yearsTy for the observation, but unfortunately it does not solve my issue. I've edited the image. Same error.
-
frasnian over 9 yearsAh, that just jumped out at me so I was hoping that was all it was. I'll take a closer look.
-
Ricardo over 9 yearsIt fixed my issue! Ty.
-
Chaitanya Gadkari almost 9 yearsmsbuild not working for me this way either, not a valid command
-
vfabre over 8 years@shyam_ are you see the steve medley comment?
-
Varlain Systems about 6 years"you should not forget the encapsulating quotes" indeed!