locked
Setting per project DEVPATH RRS feed

  • Question

  • Hi,

    I my add-in i want to configure the environment used to run C# applications, what i need is to set the DEVPATH variable in the environment that is used to run the application from Debug.Start, and Debug.StartWithoutDebugging commands.

    I have tried to modify environment DEVPATH using Environment.SetEnvironmentVariable in the before execute event for this 2 commands, but that doesn't do what i want. The assemblies are not being found.

    If i set the same environment variable manually before start Visual Studio it works, any ideas how to get this working?

    Here is an overview of my code:

    That is how i configure the event handler and it works.

    else if(c.Name.Equals("Debug.Start"))
    {
      _debugStartEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
      _debugStartEvent.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironment);
    }
    else if(c.Name.Equals("Debug.StartWithoutDebugging"))
    {
      _debugStartWithoutDebuggingEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
      _debugStartWithoutDebuggingEvent.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironment);
    }
    

    And here is how i set DEVPATH inside setDebugEnvironment implementation

    string devPath = Environment.GetEnvironmentVariable("DEVPATH");
    string customDevPath = 'C:\\mycustompath'
    if(String.IsNullOrEmpty(devPath))
    {
      Environment.SetEnvironmentVariable("DEVPATH", customDevPath);
    }
    else if(!devPath.Contains(customDevPath))
    {
      Environment.SetEnvironmentVariable("DEVPATH", customDevPath + ";" + devPath);
    }
    

    Note i want to configure DEVPATH per project, not per solution, as my add-in need to work with solutions that have several projects each of then could need to use different DEVPATH value.

    In C++ projects is easy to configure the project environment in "Configuration Properties > Debugging > Environment". but i don't see a similar feature in C#.

    Regards,

    Jose

    Wednesday, December 29, 2010 3:17 PM

Answers

  • I have investigated a bit more the issue, and here is what i have found.

    When i disabled "Enable the Visual Studio hosting process" in the projects Debug settings, things works as i want, the assemblies are loaded from the right location all the time, that is great.

    But when the hosting process is enabled, things doesn't work all the time, seems that there is some kind of caching of environment settings in the hosting process and as consequence the changes to DEVPATH are not detected in every run.

    My test case is as follow:

     

    I have a solution with two projects with use the same dlls, for each of this projects my add-in set DEVPATH to a different location

    Solution

     Project A (set DEVPATH to c:\MY_A)

     Project B (set DEVPATH to c:\MY_B)

     

    If i start Project A, i see dll loaded from MY_A, then i start project B i see dll loaded from MY_B until here all is great, then i try to start Project A  and i see dll  are loaded from MY_B that is my problem, all this when visual studio hosting process is enabled. When disabled all works fine all the time.

    Other issue i see with the hosting process is that if my application.config activate the development mode and DEVPATH is empty when Visual Studio start the hosting process crashes, i workaround this by setting something in DEVPATH when my add-in connects.

     

    So can i restart the visual studio hosting process from my add-in code?

    Can i detect if the hosting process is enabled/disabled?

    Can i detect that the application is being run in development model?

     

    Regards,

    Jose

    • Marked as answer by pepone.onrez Wednesday, January 5, 2011 4:22 PM
    Thursday, December 30, 2010 4:28 PM
  • I finaly found the way to restart vshosting process

    public static void setVsHostingProcess(Project p, bool value)
    {
      foreach(Configuration config in p.ConfigurationManager)
      {
        if(config.Properties == null)
        {
          continue;
        }
        Property property = config.Properties.Item("UseVSHostingProcess");
        property.Value = value;
      }
    }
    
    So in my code i set vshosting to false then update the environment and the set it back to true.

    Still need to know if there is a way to access the config.exe other than parse the XML? basically want to know if the application is using development mode or not

    Regards,

    Jose

    • Marked as answer by pepone.onrez Wednesday, January 5, 2011 4:22 PM
    Thursday, December 30, 2010 7:32 PM

All replies

  • I have investigated a bit more the issue, and here is what i have found.

    When i disabled "Enable the Visual Studio hosting process" in the projects Debug settings, things works as i want, the assemblies are loaded from the right location all the time, that is great.

    But when the hosting process is enabled, things doesn't work all the time, seems that there is some kind of caching of environment settings in the hosting process and as consequence the changes to DEVPATH are not detected in every run.

    My test case is as follow:

     

    I have a solution with two projects with use the same dlls, for each of this projects my add-in set DEVPATH to a different location

    Solution

     Project A (set DEVPATH to c:\MY_A)

     Project B (set DEVPATH to c:\MY_B)

     

    If i start Project A, i see dll loaded from MY_A, then i start project B i see dll loaded from MY_B until here all is great, then i try to start Project A  and i see dll  are loaded from MY_B that is my problem, all this when visual studio hosting process is enabled. When disabled all works fine all the time.

    Other issue i see with the hosting process is that if my application.config activate the development mode and DEVPATH is empty when Visual Studio start the hosting process crashes, i workaround this by setting something in DEVPATH when my add-in connects.

     

    So can i restart the visual studio hosting process from my add-in code?

    Can i detect if the hosting process is enabled/disabled?

    Can i detect that the application is being run in development model?

     

    Regards,

    Jose

    • Marked as answer by pepone.onrez Wednesday, January 5, 2011 4:22 PM
    Thursday, December 30, 2010 4:28 PM
  • I finaly found the way to restart vshosting process

    public static void setVsHostingProcess(Project p, bool value)
    {
      foreach(Configuration config in p.ConfigurationManager)
      {
        if(config.Properties == null)
        {
          continue;
        }
        Property property = config.Properties.Item("UseVSHostingProcess");
        property.Value = value;
      }
    }
    
    So in my code i set vshosting to false then update the environment and the set it back to true.

    Still need to know if there is a way to access the config.exe other than parse the XML? basically want to know if the application is using development mode or not

    Regards,

    Jose

    • Marked as answer by pepone.onrez Wednesday, January 5, 2011 4:22 PM
    Thursday, December 30, 2010 7:32 PM