Pergunta

I was trying to set up an Ogre3D application and I set an "OGRE_HOME" system variable to the home directory of the SDK. Then I set project properties, like include directories in the Project Properties, using the $(OGRE_HOME) system variable. But when I tried to compile the application, the compiler did not find the header files, so I had to "hardcode" the SDK path to the project properties.

I set the variable first with the setx command, then I tried moving it to system variables but it did not help. However I did not try to reboot the system.

Foi útil?

Solução

MSBuild does expand environment variables. $(OGRE_HOME) should work just fine.

The only problem is that Visual Studio caches the values of these environment variables heavily, so changes that you make will not be immediately reflected.

There are two general ways to change the values of environment variables, and both of these go wrong with VS:

  • Changing the values from the command line only affects applications that are launched from the command line. Since you're probably launching VS from a shortcut through Explorer, it won't inherit the new values.

  • Changing the values through Computer Properties should normally work because that dialog broadcasts a global message indicating the persistent environment variables have changed. Unfortunately, VS doesn't seem to listen to these messages and update its cache.

But, restarting (or logging off and back on) should fix the problem, as this will cause VS to refresh the values of the environment variables.

It's also worth noting that user macros are an alternative to environment variables. VS 2010 provides a very robust way of implementing these through the Property Manager. You can create a project property sheet with your settings, which can then be attached to multiple projects so that they will all inherit these settings. It doesn't work outside of VS, but it can be quite convenient if you do all of your development work there.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top