views:

2272

answers:

6

Ok, here's the breakdown of my project: I have a web project with a "Scripts" subfolder. That folder contains a few javascript files and a copy of JSMin.exe along with a batch file that runs the JSMin.exe on a few of the files. I tried to set up a post build step of 'call "$(ProjectDir)Scripts\jsmin.bat"'. When I perform the build, the batch file is always "exited with code 1." This happens going through Visual Studio or through the msbuild command line. I can run the batch file manually from the Scripts folder and it seems to work as expected, so I'm not sure what the issue here is. The $(ProjectDir)Scripts\jsmin.bat call is in quotes because $(ProjectDir) could have spaces (and in fact does on my machine). I'm not sure what to do at this point. I've tried removing the contents of the batch file as the post build step but that doesn't seem to work either.

Ideally I would like to solve this problem through the post or pre-build steps so that the build manager won't have to go through an extra step when deploying code.

Thanks!

+3  A: 

If you have something in your custom build step that returns an error code, you can add:

exit 0

as the last line of your build step. This will stop the build from failing.

Hallgrim
+1 Thanks, your answer helped me too :o)
Andrew
Although not what I ultimately ended up using, this did get past the issue I posted and leads me to believe the fault is with JSMin and the interaction from where it is being called from. Wanted to give you credit for your answer. (albeit a tad bit later)
sdanna
A: 

Somehow, and I'm not familiar with the specifics of how .bat files exit, but either JSMin or the batch file execution is exiting with a non-zero return code.

Have you tried running the scripts directly (i.e. not through JSMin.bat) as part of the post-build?

Edit: Looks Hallgrim has it.

Sam Erwin
A: 

@Hallgrim: Adding that did make the build continue, however the batch file was still not run successfully.

@Sam: Interestingly enough, no it does not. I can even put the full path to the JsMin.exe and it does not work. Weird stuff.

The commands I have tried unsuccessfully are below:

call "[full path]\jsmin.exe [jsmin params]"
call [full path]\jsmin.exe [jsmin params] (no quotes)
"[full path]\jsmin.exe [jsmin params]"
[full path]\jsmin.exe [jsmin params] (no quotes)

I just don't get why I can double click on the batch file from windows explorer and it works. From what I understand, VS just takes the input you specify, changes the token values and then executes them like in a command window. I'm stumped.

sdanna
+1  A: 

Do your script or batch files use any path references internally?

I've found that batch files will not work correctly if path references are not fully qualified.

Example: a batch file called DoStuff.bat uses the echo command to append a text file.

This does not work inside the .bat file:

echo "test" >>"test.txt"

This does work inside the .bat file:

echo "test" >>"C:\Temp\CompileTest\test.txt"

The Visual Studio Post-build event command line is this:

call "C:\Temp\CompileTest\DoStuff.bat"
Jonathan Webb
Calling "C:\Temp\CompileTest\DoStuff.bat" does not change the Windows current directory, so current dir stays at some random value and test.txt (which is a relative path to current dir) probably appears there. See the solution from Gustav.
Martin Konicek
A: 

Getting back to this issue now (had to move onto other fires for a bit)

@Jonathan Webb - I tried some the ideas but with no success. In fact I learned we are doing something similar (calling an external program using post build tasks) in other internal projects. I'm inclined to believe it is some interaction with the jsmin.exe tool or some other foolish error on my part.

All is not lost however, another developer turned my attention to the YUI Compressor and its implementation in .NET. Through some manual .csproj manipulation I was able to achieve my goals and then some (including CSS compression)!

sdanna
+1  A: 

A working sollution for this that i use:

CD $(ProjectDir)

DoStuff.bat

No call commands or anything else is needed, this of course if you have the file in your project directory.

This works for me, while "$(ProjectDir)DoStuff.bat" does not work. This is because in DoStuff.bat I use relative paths, and calling "$(ProjectDir)DoStuff.bat" does not change the current directory, so current dir stays at some random value and the paths are pointing to bad destinations.
Martin Konicek