Visual Studio 2012 Post Build Events - Error Code 255

Here is my attempt to copy the application executable to another folder by changing its 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 tried everything to make it work, but it always gives an error code of 255 or 1, it depends. Running this code with a simple batch file works like a spell!

+4
source share
2 answers

You need to enable delayed expansion using the SETLOCAL EnableDelayedExpansion command . Do this at the top of the post-build event. After that, you can access your variable using not% VARIABLE_NAME%, but! VARIABLE_NAME! (use an exclamation mark on both sides of the variable name, not the percentage character that you will 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. 
+3
source

Since the command line of the Post-build event actually fires as a batch file, you need to avoid characters like% by doubling them to %%:

fooobar.com/questions/93508 / ...

+1
source

Source: https://habr.com/ru/post/1481850/


All Articles