Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post build SET command and %variable% error

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:

""
""
like image 760
SynerCoder Avatar asked Aug 17 '12 11:08

SynerCoder


2 Answers

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%"
like image 107
rene Avatar answered Oct 01 '22 13:10

rene


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"
)
like image 29
SynerCoder Avatar answered Oct 01 '22 12:10

SynerCoder