locked
Addin/Package: How to programmatically change Project.ConfigurationManager.ActiveConfiguration? RRS feed

  • Question

  • PLATFORM: Visual Studio 2008 SP1.
    ******************************
    If I execute this code (from an addin):

       // Select the Win32|Debug Solution Build Configuration ... omitted here for brevity
    
       SolutionConfiguration sc = _applicationObject.Solution.SolutionBuild.SolutionConfigurations ... "Win32|Debug"
    
    
    
       sc.Activate();
    
    
    
       // Pick a C++ project
    
       Project theProject = _applicationObject.Solution.Projects.Item(1);
    
    
    
       Configuration c = theProject.ConfigurationManager.ActiveConfiguration;
    
    
    
    

    Then I get whatever active Project Configuration is selected for the Solution Build Configuration 'Win32|Debug'. I can see the active Project Configuration for theProject if I go into 'Build/Configuration Manager' and the two tie up. As expected.

    In 'Build/Configuration Manager', I can change the ConfigurationName of theProject - perhaps to Release - and that is reflected in the active project configuration for theProject when I rerun the above code. As expected. All is rosy.

    The question is: how do I PROGRAMMATICALLY change the project.ActiveConfiguration property? It is read only.
     
    RATIONALE: This requirement is merely visual. If, for a particular Solution Build Configuration - say Win32|Debug - I want to build the 'x64|Release' Project Configuration, I know I can do this using the Solution Contexts. I know I can do this, manually, using the Solution Build Configuration dialog box by simply changing the Platform to 'x64' and the ConfigurationName to 'Release' for theProject. What I want to do is to programmatically change the Active Project Configuration for 'theProject' in a given Solution Build Configuration so the user can see the actual Project Configuration that is being built when they open the Solution Build Configuration dialog box.

    Any help would be appreciated. Thankyou!

    • Edited by Grey Ham Tuesday, March 2, 2010 2:28 PM Tidy up paragraph
    Tuesday, March 2, 2010 2:26 PM

Answers

  • Hi Grey,

    Based on my research, I have not found a way to modify project platform name programmatically. If you want to modify solution configuration name, you can refer to following code:


    SolutionConfiguration2 activeSlnConfig = (SolutionConfiguration2)
    _applicationObject.Solution.SolutionBuild.ActiveConfiguration; SolutionContext sln = activeSlnConfig.SolutionContexts.Item(1); sln.ConfigurationName = "Debug";

    Since Configuration.PlatformName is read only, we can't assign string to it. So I don't think we can modify it programmatically.

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Nancy Shao Wednesday, March 10, 2010 9:23 AM
    Thursday, March 4, 2010 6:47 AM

All replies

  • Hi Grey,

    Based on my research, I have not found a way to modify project platform name programmatically. If you want to modify solution configuration name, you can refer to following code:


    SolutionConfiguration2 activeSlnConfig = (SolutionConfiguration2)
    _applicationObject.Solution.SolutionBuild.ActiveConfiguration; SolutionContext sln = activeSlnConfig.SolutionContexts.Item(1); sln.ConfigurationName = "Debug";

    Since Configuration.PlatformName is read only, we can't assign string to it. So I don't think we can modify it programmatically.

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Nancy Shao Wednesday, March 10, 2010 9:23 AM
    Thursday, March 4, 2010 6:47 AM
  • If you want to modify solution configuration name, you can refer to following code:


    SolutionConfiguration2 activeSlnConfig = (SolutionConfiguration2)<br/>    _applicationObject.Solution.SolutionBuild.ActiveConfiguration;
    SolutionContext sln = activeSlnConfig.SolutionContexts.Item(1);
    sln.ConfigurationName = "Debug";
    
    


    I tried this code because I need to set the configuration, but when I debug the code, the ConfigurationName property doesn't change and there is no exception thrown or error specified. Conclusion; doesn't work.

    Does someone have an idea why?

    Thanks in advance.

    • Proposed as answer by Girishprb Tuesday, September 6, 2011 3:44 AM
    • Unproposed as answer by Girishprb Tuesday, September 6, 2011 3:44 AM
    Tuesday, July 13, 2010 7:54 PM
  • does soution.SolutionBuild.Deploy(true) help ??
    Tuesday, September 6, 2011 3:45 AM