I\'m trying to execute a batch file during a pre-build event. I have a new project and have added foo.bat to it. The file contains the following line:
The current working directory of the pre-build and post-build events is the output directory specified by the macro $(OutDir), not the project directory.
The following tags in "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets" specify this:
<Target
Name="PreBuildEvent"
Condition="'$(PreBuildEvent)'!=''"
DependsOnTargets="$(PreBuildEventDependsOn)">
<Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" />
</Target>
<Target
Name="PostBuildEvent"
Condition="'$(PostBuildEvent)' != '' and ('$(RunPostBuildEvent)' != 'OnOutputUpdated' or '$(_AssemblyTimestampBeforeCompile)' != '$(_AssemblyTimestampAfterCompile)')"
DependsOnTargets="$(PostBuildEventDependsOn)">
<Exec WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)" />
</Target>
I solved the problem by creating the .bat file from windows explorer, and then in turn including it into my project, instead of creating in directly in VS 2010.
The problem I suspect is that there's a SPACE character in your folder path.
So this command will probably work for c:\development\projectABC\foo.bat
but not for c:\development\project ABC\foo.bat
At least that was the problem for me, there could be other issues, but I suspect this is the most common. The solution: put quotation marks around you batch call:
"c:\development\project ABC\foo.bat"
1) see error details by View => Output 2) try call "$(SolutionDir)\xx\xx.bat"
Right click the project --> select properties --> select build event Tab Then Clear the Pre-Build event comment lines.
I got this working and I figure a picture is worth a thousand words, so here is the full setup in a single screenshot.