4

Is it possible to get the value of $(ProjectDir) or $(SolutionDir) programatically outside Visual Studio? My scenario is I need to read a vcproj file as a text file and get its properties like the outputdirectory etc.. problem is some properties contain environment variables like $(SolutionDir) and the like.

Bob Kaufman
  • 12,215
  • 15
  • 76
  • 102
3ggerhappy
  • 223
  • 2
  • 4
  • 13

1 Answers1

4

Well, you found out that looking at the .vcproj file isn't enough. You need to know the .sln file as well. You're kinda stuck until you resolve this. Visual Studio will always create a .sln file when it loads a .vcproj file and cannot find a matching .sln. Maybe you want to do that too.

Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371
  • 1
    I dont have a problem with the solution file, I can read the .sln format fine. I just need to get the value of the variable $(ProjectDir),$(SolutionDir).e.g taken from a vc proj file *** OutputDirectory="$(ProjectDir)$(ConfigurationName)" – 3ggerhappy Feb 02 '11 at 15:59
  • 5
    Well, you know the values, $(ProjectDir) is the directory where you found the .vcproj file, $(SolutionDir) is the directory where you found the .sln file. – Hans Passant Feb 02 '11 at 16:16
  • I see how about $(ConfigurationName) what does it mean?, also I have got one project where OutputDirectory="$(ProjectDir)Bin" does it mean e.g C:\MYprojectDir\Bin – 3ggerhappy Feb 02 '11 at 19:01
  • That's a selection made when you build. Debug or Release by default. And yes. – Hans Passant Feb 02 '11 at 19:05
  • Hi Sorry for bringing this up again but is there a way to determine $(ConfigurationName) wether DEbug or Releae just by looking in the vcproj file, if not can you please suggest – 3ggerhappy Feb 07 '11 at 20:11
  • No, this is stored in the hidden .suo file, you cannot read it. It is random anyway, whatever was last used in the IDE. – Hans Passant Feb 07 '11 at 20:15
  • No one actually answered the OP's question. I, for one, would like to know how to access the value of these many macro values. Yes, you can sort of figure out what they "should" mean, but how can you actually print/debug/watch the value each contains and know with certainty what string, say, $(SolutionDir) is resolving to? – Jazimov Feb 27 '14 at 23:35
  • This post answered the question for me--sort of. You're not actually printing the value programmatically but you can see it in the Visual Studio IDE: http://stackoverflow.com/questions/3423538/executing-projectdir – Jazimov Feb 27 '14 at 23:58