locked
Environment Variables In Property Sheets? RRS feed

  • Question

  • Hi Folks:

       Developing on Win 10 Pro, VS 2017 Community.

       A property sheet I wrote contains two paths to header files. 

       I've been hard coding those path and everything's been working fine. 

       I'd like to have the flexibility of using an environment variables as part of the specification for the path:

      <PropertyGroup Label="UserMacros" />
      <PropertyGroup>
        <IncludePath>%UTILITIES_PATH%\code\unix_files\unix_include;%UTILITIES_PATH%\code\windows_files\headers;$(IncludePath)</IncludePath>
      </PropertyGroup>
      <ItemDefinitionGroup />
      <ItemGroup />
    </Project>

       Now it's throwing a lot of errors like this:

    5>d:\utilities\code\windows_files\XXX.cpp(8): fatal error C1083: Cannot open include file: 'error_utilities.h': No such file or directory
       If I paste "%UTILITIES_PATH%\code\windows_files\headers" into the path for a File Explore window:


       Can I use environmental variables in property sheets?

    Thanks
    Larry

    Thursday, April 26, 2018 11:11 AM

Answers

  • I think Visual Studio should expose environment variables as macros. You should be able to figure this out in Visual Studio itself easily enough.

    As you should know, you can open the edit window for a property if you click on the little down arrow when you have a property selected.

    If you click the down arrow, the button at the right hand side in my screenshot, you can select <Edit...> and this will bring up the edit window.

    At the bottom is the Macros>> button, this will expand the window to show the macro list.

    This does include environment variables, since from the last screenshot you can see ALLUSERSPROFILE and APPDATA, which if you check the list of environment variables defined for your user account using the set command, then these will normally be the first two.

    So instead of %UTILITIES_PATH%, try $(UTILITIES_PATH).


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Proposed as answer by RLWA32 Thursday, April 26, 2018 12:44 PM
    • Marked as answer by a_unique_name Thursday, April 26, 2018 11:38 PM
    Thursday, April 26, 2018 12:38 PM

All replies

  • Does the value for %UTILITIES_PATH% include embedded spaces?
    Thursday, April 26, 2018 11:17 AM
  • I think Visual Studio should expose environment variables as macros. You should be able to figure this out in Visual Studio itself easily enough.

    As you should know, you can open the edit window for a property if you click on the little down arrow when you have a property selected.

    If you click the down arrow, the button at the right hand side in my screenshot, you can select <Edit...> and this will bring up the edit window.

    At the bottom is the Macros>> button, this will expand the window to show the macro list.

    This does include environment variables, since from the last screenshot you can see ALLUSERSPROFILE and APPDATA, which if you check the list of environment variables defined for your user account using the set command, then these will normally be the first two.

    So instead of %UTILITIES_PATH%, try $(UTILITIES_PATH).


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Proposed as answer by RLWA32 Thursday, April 26, 2018 12:44 PM
    • Marked as answer by a_unique_name Thursday, April 26, 2018 11:38 PM
    Thursday, April 26, 2018 12:38 PM
  • Thanks RLWA32:
    Does the value for %UTILITIES_PATH% include embedded spaces?
    Nope,  just "D:\utilities", like it expands to in the address line of the File Explore window.
    Thursday, April 26, 2018 12:39 PM
  • Darran Rowe's post has the solution.
    Thursday, April 26, 2018 12:45 PM
  • Thanks Darran and RLWA32:

     Representing the environment variable as a macro fixed it.

    Larry

    Thursday, April 26, 2018 11:38 PM