2

My post build command is

call "$(ProjectDir)MyFile.bat"

And getting build error:

Error 1 The command "call C:\MyProject\MyFile.bat" exited with code 1. C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets 4548 5

What am I missing here? Working on TFS source code, is that the reason getting this error?

For testing in MyFile.bat the only code is mkdir MYTestFolder, but then I am also getting the same error.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Neo
  • 15,491
  • 59
  • 215
  • 405
  • This question seems to indicate my answer is completly wrong, but then I would say the call to the batch file is working, but the batch is failing. http://stackoverflow.com/questions/1491394/can-we-execute-a-bat-file-in-post-build-event-command-line-in-visual-studio – miltonb Jun 24 '15 at 20:44
  • `mkdir` is not a complete batch command. – Tom Blodget Jun 25 '15 at 05:38
  • sorry for typo i did it like `mkdir MYTestFolder` – Neo Jun 25 '15 at 06:09

2 Answers2

2

It seems like the syntax of the call is correct. Therefore I believe it's failing inside the batch file. I suggest putting the first few lines of the batch to write the time into a log file, so you can confirm it's being called. Do this before any of the actual work, so it can be sure that the batch is being executed.

call "$(ProjectDir)MyFile.bat"

MyFile.bat

@echo off
echo time /t > MyTempFolderPath\logfile.txt
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
miltonb
  • 6,905
  • 8
  • 45
  • 55
  • getting same error.. is it necessary to execute `cmd.exe` before `.bat`? `C:\Windows\System32\cmd.exe call MyFile.bat` ?? is it ? – Neo Jun 24 '15 at 09:51
  • for testing in MyFile.bat only code is `mkdir MyTestFolder` then also getting same error – Neo Jun 25 '15 at 06:10
  • 1
    I have zero ideas left. It seems like everything should work. – miltonb Jun 25 '15 at 21:17
  • same here :( i dont know how and where to troubleshoot :/ – Neo Jun 26 '15 at 04:14
  • Also we can use this to run build events in Debug only ```if $(ConfigurationName) == Debug ( call "$(ProjectDir)prebuild.bat" ) ``` – Abdallah Okasha Feb 02 '23 at 07:39
0

It is the code inside the batch file that is failing - what is it doing?

You have a few options:

a - I would use process monitor and watch process exits and see the status codes of whatever the batch file launches.

b - You could also try running the batch file from the same folder as msbuild and see if you get any errors

Ed

Ed Elliott
  • 6,666
  • 17
  • 32
  • for testing in MyFile.bat only code is `mkdir MyTestFolder` then also getting same error – Neo Jun 25 '15 at 06:10
  • 1
    I guess that it can't find MyFile.bat - use procmon and setup a filter for "path contains MyFile.bat" - $(ProjectDir) probably isn't resolving either at all or where you think it is See: http://stackoverflow.com/questions/985900/tfs-msbuild-projectdir-blank-or-random) – Ed Elliott Jun 25 '15 at 08:08
  • in procmon unable to find file `MyFIle.bat` ? – Neo Jun 26 '15 at 04:27