Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 Post Build Events - Error Code 255

Here is my attempt to copy my application executable to another folder changing it's name:

IF $(ConfigurationName) == Release (
    SET DESTINATION=$(ProjectDir)Output\Distribution

    IF NOT EXIST "%DESTINATION%" ( MD "%DESTINATION%" )

    XCOPY /Q /Y "$(TargetPath)" "%DESTINATION%"
    RENAME "%DESTINATION%\$(TargetFileName)" "$(TargetName).Plain$(TargetExt)"
)

I've tried everything to make it work, but it always throw error code 255 or 1, it depends. Running that code with a plain batch file works like a charm!

like image 326
Tommaso Belluzzo Avatar asked May 21 '13 00:05

Tommaso Belluzzo


People also ask

How to exit SharePoint with error code 255?

" exited with code 255. SharePointDemo Kindly help us out. Try replacing "call" with "cmd /c". The error code "255" usually means that it is not able to find the file you are asking it to execute. "call" is usually used inside batch or command files and not directly as an exectuable.

What does the error code 255 mean?

Thanks for using MSDN forum. The error code 255 usually means it's not able to find the file you are asking it to execute. What's your command line? Have you checked if the path of the file you are asking is correct?

How do I set up pre-build and post-build events?

You can type pre- or post-build events for the Build Events Page, Project Designer (C#) directly in the edit box, or you can select pre- and post-build macros from a list of available macros. Pre-build events do not run if the project is up to date and no build is triggered. Contains the events to run either for pre-build or post-build.


2 Answers

You need to enable delayed expansion, using the SETLOCAL EnableDelayedExpansion command. Do it at the top of the post-build event. After that, you can access your variable by using not %VARIABLE_NAME%, but !VARIABLE_NAME! (use an exclamation symbol on either side of the variable name, not the percentage symbol which you would use in a regular batch file).

So, for example

SETLOCAL EnableDelayedExpansion
IF $(ConfigurationName) == Release (
    SET DESTINATION=$(ProjectDir)Output\Distribution
    echo My destination dir is !DESTINATION!
)

This will output something like

My destination dir is D:\Work\Projects\PBExample\Output\Distribution.
like image 125
Daniël Teunkens Avatar answered Sep 21 '22 12:09

Daniël Teunkens


Since the Post-build event command line actually runs as a batch file you need to escape characters like % by doubling them to %%:

https://stackoverflow.com/a/13552702/74585

like image 35
Matthew Lock Avatar answered Sep 21 '22 12:09

Matthew Lock