locked
How to set environment variable after solution file is chosen, but before it is loaded? RRS feed

  • Question

  • I'm trying to set an environment variable based on the solution file that is picked.  I've tried to do this by creating a add-in that will catch a OnBeforeSolutionOpened event.  However, from what I can tell, there isn't an event like that... I have found an event that is triggered after the solution is opened, but that is arlready too late... 
    Is there any other event that gets called before a solution is opened, but after it is chosen (so I can get the filename)?  It doesn't have to be a perfect fit -- I'm ok with an event that is called more times than it I need, given that what I will do will be a quick operation... 


    If this isn't possible, any other ideas?  I would love to be able to create a environment variable through the solution file, but I don't see a way of doing that either... At least, not that I have found...


    Thanks for any help in advance!

    Tom
    • Edited by tmaslach Thursday, September 11, 2008 4:39 AM
    Thursday, September 11, 2008 4:37 AM

Answers

  • The simplest approach I can work out will be to write a solution launcher script in which we can detect and set the ROOTDIR environment variable according to the solution file to be opened, and then open it using Visual Studio.

    And I strongly recommended that you can submit this issue as a feature request to the following site in the formal way: http://connect.microsoft.com/VisualStudio/

    After you submit it, we will appreciate it if you can share the feedback address so that it can be found and checked out by other community members having similar issues.

    Hope this helps.

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Feng Chen Tuesday, September 16, 2008 3:43 AM
    Friday, September 12, 2008 7:15 AM

All replies

  • Is there any other event that gets called before a solution is opened, but after it is chosen (so I can get the filename)?
    So far as I know, we have not expose such an event can let you achieve this. For more information, please visit Executing code every time a solution is about to be opened.

    Thanks.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, September 11, 2008 9:47 AM
  • Let me explain my problem -- maybe someone here can think of a different, clever solution..

    We have defined all our paths in our build system ("Additional Include Directories", "Additional Library Dependencies", etc..) relative to a rootdirectory.. So, when including an include path, we do: "$(ROOTDIR)/path_under_root".

    Right now, we have to go to a DOS prompt, set an environment variable, then launch DevStudio... This works, but is a tedious way to do things.  We are trying to come up with a system that works automatically within DevStudio -- which is what I was trying to do with the plugin..

    Here are two of my other ideas on how I tried to solve this:
    1. We use property sheets pretty extensively and would like to define ROOTDIR in the top level property sheet (which itself resides in ROOTDIR).  However, there is no property sheet macro for getting the directory the current property sheet is in.  

    2. I've also thought about setting a macro through the solution .xml file (since I beleive a macro will be used when $(ROOTDIR) is specified).  However, I haven't found any good documentation on whether this can even be done yet..

    Are any of these methods sound like they might work?  Any ideas if there is another method I have missed?  Thanks,


    Tom


    Edit:

    Let me add one more thing... If I don't get this ROOTDIR set somehow, the project fails to load.. Maybe I can use that as a hook somehow?
    • Edited by tmaslach Thursday, September 11, 2008 2:27 PM
    Thursday, September 11, 2008 2:09 PM
  • The simplest approach I can work out will be to write a solution launcher script in which we can detect and set the ROOTDIR environment variable according to the solution file to be opened, and then open it using Visual Studio.

    And I strongly recommended that you can submit this issue as a feature request to the following site in the formal way: http://connect.microsoft.com/VisualStudio/

    After you submit it, we will appreciate it if you can share the feedback address so that it can be found and checked out by other community members having similar issues.

    Hope this helps.

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Feng Chen Tuesday, September 16, 2008 3:43 AM
    Friday, September 12, 2008 7:15 AM