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:

""
""
SynerCoder
  • 12,493
  • 4
  • 47
  • 78

2 Answers2

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%"
rene
  • 41,474
  • 78
  • 114
  • 152
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"
)
SynerCoder
  • 12,493
  • 4
  • 47
  • 78