10

I want to use local variable inside the PostBuild event, but I could not understand how to use it inside. Here my Post-Build event commands (param is the named parameter that can be passed through the msbuild /p switch):

set fold=$(TargetDir)
if defined param (set fold=$(TargetDir)$(param)\)
if not exist "%fold%" md "%fold%"
copy /y "$(TargetPath)" "%fold%"

When building the solution I get:

msbuild PrePostBuildEvents.sln /p:param=ext

...

PostBuildEvent:
  set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\
  if defined param (set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\ext\)
  if not exist "%fold%" md "%fold%"
  copy /y "G:\prj\work\PrePostBuildEvents\bin\Debug\PrePostBuildEvents.dll" "%fold%"
  The file cannot be copied onto itself.
          0 file(s) copied.

If I change %fold% to $(fold), I get another result, but it is also wrong:

PostBuildEvent:
  set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\
  if defined param (set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\ext\)
  if not exist "" md ""
  copy /y "G:\prj\work\PrePostBuildEvents\bin\Debug\PrePostBuildEvents.dll" ""
  The filename, directory name, or volume label syntax is incorrect.
          0 file(s) copied.

What I'm doing wrong?

2
  • I'm not near my Windows machine, but in VS there is a resource tab in the the project properties , I think you define it there. you can check or I will later when I be near my Win machine Commented Jan 19, 2014 at 17:32
  • I assume that I can define only a constant string there, but I need calculatable one, that depends on named parameters. Commented Jan 20, 2014 at 4:07

1 Answer 1

2

Firstly, use the AfterBuild msbuild target rather than PostBuild event. This will give msbuild more information about what you're trying to do and done correctly should mean a faster incremental compile.

Environment variables can be used in AfterBuild events: http://msdn.microsoft.com/en-us/library/ms171459.aspx

Ideally once you've run msbuild once, when you run it a second time it should do no work skipping compiles and not bothering to copy things around as the files are already there.

Sign up to request clarification or add additional context in comments.

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.