M-A's

technology blog

Thursday 17 January 2008

Understanding vsprops files

I've began using .vsprops files (along side .vcproj files) on VS2005 SP1. I discovered that you can do something that looks like that:
< ?xml version="1.0" encoding="Windows-1252"? >
< VisualStudioPropertySheet
projecttype="Visual C++"
version="8.00"
name="whatever" inheritedpropertysheets=".\randomprefix_$(RANDOM_ENVIRONMENT_VARIABLE).vsprops">
< /VisualStudioPropertySheet >
This is cool, you can modify which vsprops file will be inherited by an externally defined environment variable, before starting Visual Studio. Ok fine, then try further:
< ?xml version="1.0" encoding="Windows-1252"? >
< VisualStudioPropertySheet
projecttype="Visual C++"
version="8.00"
name="whatever" inheritedpropertysheets="$(SolutionDir)..\randomdir\random_file.vsprops">
< /VisualStudioPropertySheet >
Cool again! I can use locally defined variable in Visual Studio. Ok, then let's try to do something useful:
< ?xml version="1.0" encoding="Windows-1252"? >
< VisualStudioPropertySheet
projecttype="Visual C++"
version="8.00"
name="whatever" inheritedpropertysheets="randomprefix_$(ConfigurationName).vsprops">
< /VisualStudioPropertySheet >
It fails. :( That would have been useful: include a vsprops file named after the current configuration name (debug or release or whatever). Here a counter example:
< ?xml version="1.0" encoding="Windows-1252"? >
< VisualStudioPropertySheet
projecttype="Visual C++"
version="8.00"
name="whatever" outputdirectory="$(SolutionDir)$(ConfigurationName)" >
< /VisualStudioPropertySheet >
Yes, that actually works. In fact, you can even set « CharacterSet="1" » in the vsprops even if the VS vsprops editor doesn't allow you to set this (the same applies to WholeProgramOptimization). So it seems like $(ConfigurationName) and $(SolutionDir) aren't defined at the same time, which is normal. The way VS looks at the project file looks like this:

  1. Initial parsing
  2. For each Configuration in Configurations
    1. Load the InheritedPropertySheets attribute
      1. Open recursively the property sheets
    2. Load the Name attribute in Configuration in the vcproj
    3. Process property sheets
    4. Process the rest of the attributes
    5. Load the rest
The thing is that you can use $(ConfigurationName) in the OutputDirectory attribute but not in the InheritedPropertySheet. Too bad, what a missed opportunity. I somewhat tried playing with UserMacro but without any success.

Disclaimer: I didn't try with VS2008.
Disclaimer: I know the blogger's editor sucks and that I couldn't write real XML. In fact, they know it too. I just wished they cared. We're just all eager to have it actually fixed.

3 comments:

Anonymous said...

actually I use
$(SolutionDir)$(PlatformName)-$(ConfigurationName).vsprops
as value for the inherited property sheet and it works fine for me!

Unknown said...

I always used the interactive editor or offline .vcproj/.vsprops editing.

I never tried automation. From the comments on the bug Mike referred, it looks like the VS team really don't care.

Anonymous said...

On VS 2008
$(SolutionDir) is working but not
$(PlatformName) or$(ConfigurationName) for inherited property sheets paths/names.

I tried thomas's suggestion but no go - it's as was said on the original post.
Note: If the file doesn't exist when adding in GUI it removes it - press apply to see. If you edit manually then load the project the project fails to load.