8

I am a batch newbie and I might have made a mistake. But I have the following post-build event:

IF $(ConfigurationName) == Release (
    SET RELEASEPATH = "C:\Users\Synercoder\Documents\Visual Studio 2010\Releases\$(ProjectName)"
    IF NOT EXIST  %RELEASEPATH% (
        GOTO MAKEDIR
    ) ELSE (
        GOTO DIREXISTS
    )
    :MAKEDIR
    MKDIR %RELEASEPATH%
    :DIREXISTS
    COPY /Y "$(TargetDir)$(ProjectName).dll" "%RELEASEPATH%\$(ProjectName).dll"
    COPY /Y "$(TargetDir)$(ProjectName).pdb" "%RELEASEPATH%\$(ProjectName).pdb"
)

But this fails with code 255. If I replace all the %RELEASEPATH% with the actual path it works. I looked up the SET command and I think that I used it right... But like I said I am a batch newbie.

Any clue why this fails in my case?

If I use the following code this is my output:

SET RELEASEPATH = test
ECHO "%RELEASEPATH%"
SET RELEASEPATH = "test"
ECHO "%RELEASEPATH%"

Output:

""
""

2 Answers 2

13

First of all, spaces do matter! I would remove the " if I were you and only add them when the var is used.

SET RELEASEPATH=C:\Users\Synercoder\Documents\Visual Studio 2010\Releases\$(ProjectName)

IF NOT EXIST  "%RELEASEPATH%" MKDIR "%RELEASEPATH%"
Sign up to request clarification or add additional context in comments.

3 Comments

if I use SET RELEASEPATH=C:\Users\Synerc... with or without quotes ("C:\...") doesnt matter. Still the same (see extra example)
Damnit! I was looking into the "" forgot the spaces. Thx you saved my day.
for me it worked only after I put IF NOT EXIST "%RELEASEPATH%" MKDIR "%RELEASEPATH%" in one line
4

My solution was the following:

SET RELEASEPATH=%USERPROFILE%\Documents\Visual Studio 2010\Releases\$(ProjectName)
IF $(ConfigurationName) == Release (
    IF NOT EXIST %RELEASEPATH% (
        MKDIR "%RELEASEPATH%"
    ) 
    COPY /Y "$(TargetDir)$(ProjectName).dll" "%RELEASEPATH%\$(ProjectName).dll"
    COPY /Y "$(TargetDir)$(ProjectName).pdb" "%RELEASEPATH%\$(ProjectName).pdb"
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.