title: How to pass all Visual Studio 2008 "Macros" to Python script?
body: <p><em>[NOTE: This questions is similar to but <strong>not the same</strong> as <a href="https://stackoverflow.com/questions/128634/how-to-use-system-environment-variables-in-vs-2008-post-build-events">this one</a>.]</em></p>
  
  <p>Visual Studio defines several dozen "Macros" which are sort of simulated environment variables (completely unrelated to C++ macros) which contain information about the build in progress.  Examples:</p>
  
  <pre>
      ConfigurationName  Release
      TargetPath         D:\work\foo\win\Release\foo.exe
      VCInstallDir       C:\ProgramFiles\Microsoft Visual Studio 9.0\VC\
  </pre>
  
  <p>Here is the complete set of 43 built-in Macros that I see (yours may differ depending on which version of VS you use and which tools you have enabled):</p>
  
  <pre>
      ConfigurationName  IntDir           RootNamespace      TargetFileName
      DevEnvDir          OutDir           SafeInputName      TargetFramework
      FrameworkDir       ParentName       SafeParentName     TargetName
      FrameworkSDKDir    PlatformName     SafeRootNamespace  TargetPath
      FrameworkVersion   ProjectDir       SolutionDir        VCInstallDir
      FxCopDir           ProjectExt       SolutionExt        VSInstallDir
      InputDir           ProjectFileName  SolutionFileName   WebDeployPath
      InputExt           ProjectName      SolutionName       WebDeployRoot
      InputFileName      ProjectPath      SolutionPath       WindowsSdkDir
      InputName          References       TargetDir          WindowsSdkDirIA64
      InputPath          RemoteMachine    TargetExt             
  </pre>
  
  <p>Of these, only four (<code>FrameworkDir</code>, <code>FrameworkSDKDir</code>, <code>VCInstallDir</code> and <code>VSInstallDir</code>) are set in the environment used for build-events.</p>
  
  <p>As Brian mentions, user-defined Macros can be defined such as to be set in the environment in which build tasks execute.  My problem is with the built-in Macros.</p>
  
  <p>I use a Visual Studio Post-Build Event to run a python script as part of my build process.  I'd like to pass the entire set of Macros (built-in and user-defined) to my script in the environment but I don't know how.  Within my script I can access regular environment variables (e.g., Path, SystemRoot) but NOT these "Macros".  All I can do now is pass them on-by-one as named options which I then process within my script.  For example, this is what my Post-Build Event command line looks like:</p>
  
  <pre>
      postbuild.py --t="$(TargetPath)" --c="$(ConfigurationName)"
  </pre>
  
  <p>Besides being a pain in the neck, there is a limit on the size of Post-Build Event command line so I can't pass dozens Macros using this method even if I wanted to because the command line is truncated.</p>
  
  <p>Does anyone know if there is a way to pass the entire set of Macro names and values to a command that does NOT require switching to MSBuild (which I believe is not available for native VC++) or some other make-like build tool?</p>