3

I recently started adding Post-Build events to my projects and today I came across an annoying issue.

Post-build event command line:

"$(ProjectDir)PostBuildRelease.bat"

PostBuildRelease.bat - 1

CMD
SET parameter=%1
CD %1

The above errors with message:

'´╗┐CMD' is not recognized as an internal or external command,

operable program or batch file.

"Saved parameter "

Which is strange, because I definitely have another project where the first line reads CMD and it works perfectly.

Setting the first line to SET parameter=%1 also complains that SET is not a recognised command.

PostBuildRelease.bat - 2

Trying the same but with an empty file gives this error (build fails):

The command "C:\Users\name\ITSelfHelp\ITHelp\PostBuildRelease.bat" exited with code 1.

PostBuildRelease - 3

Entering the CMD code directly into the Post-Build Event command line field results in a successful post-build event, but this is not ideal for me and seems strange as I can run from an external .bat in other projects.

Can anyone explain this behaviour, or let me know how I can debug this?

Community
  • 1
  • 1
Bassie
  • 9,529
  • 8
  • 68
  • 159
  • 1
    Based on the error text you've shown, it looks as if you have some non-printable characters before the `CMD` text. Look closely at what is shown between the single quotes in the error message: _'´╗┐CMD' is not recognized as an internal or external command_ – David Tansey Sep 09 '16 at 15:49
  • 1
    Take a look at this post: http://superuser.com/questions/601282/%CC%81-is-not-recognized-as-an-internal-or-external-command or this one: http://stackoverflow.com/questions/854360/visual-studio-inserts-invalid-characters-in-batch-files – David Tansey Sep 09 '16 at 15:50

1 Answers1

3

It turns out the text editor in Visual Studio was encoding my batch script.

To recreate this:

  • Right-click the solution
  • Add file
  • Text file
  • Rename file.bat
  • Write the script in Visual Studio
  • Build
  • Check the output window for the error

To resolve:

  • Delete the file created in Visual Studio
  • Created a new .bat file in the same location using Windows Explorer
  • Open the file with Notepad++ and paste in the script
  • Save and build

I also noticed that syntax highlighting was not being applying in the file created by Visual Studio, which is a bit of a giveaway along with the ´╗┐ in front of the errors.

Bassie
  • 9,529
  • 8
  • 68
  • 159