locked
Save startup project changes RRS feed

  • Question

  • Hi,

    I'm changing the startup project like this:

    m_applicationObject.Solution.SolutionBuild.StartupProjects = sProjName;

    where m_applicationObject is the DTE2 object and sProjName is the project's unique name.

    I see that the startup project changes fine but when I close the solution, the information doesn't persist meaning that the next time I open the solution, the previous startup project is selected. To be more clear:

    1. Open Solution with ProjA and ProjB (ProjA is the startup project)
    2. Change startup project to ProjB (programmatically using the code above)
    3. The change is successful and we see on Solution Explorer that ProjB is the new startup project
    4. Close Solution
    5. Reopen Solution and ProjA is the startup project (but the startup proj should be ProjB)

    When I do it manually through VS by right clicking the ProjB and picking Set as startup project everything works as expected and the changes persist when we close the solution.

    How can I achieve the same behaviour?

    Thank you,
    Ricardo.


    Ricardo Sabino --- http://www.ricardosabino.com




    • Edited by n0n4m3 Friday, March 7, 2014 6:51 AM
    Friday, March 7, 2014 6:48 AM

Answers

  • Hi,

    Thank you for your feedback!

    Has your problem been solved?

    From the document "SolutionBuild.StartupProjects Property ", we see it can get or set the names of projects that are entry points for the application.

    I guess it may be a time-delay. Have you tried with a loop or set a timer?

    Best regards,

    Sunny

    • Marked as answer by Anna Cc Wednesday, June 25, 2014 11:25 AM
    Tuesday, April 1, 2014 7:57 AM

All replies

  • Hi,

    I know how to detect when the user sets the startup project manually and I know how to detect when a project is removed from the solution but I don't know how to check that the startup project changed when the user removes the current startup project from the solution.

    The event argument that is sent when I listen to the project removed event is the current project but if I try to look for the current startup project, it will still be the previous project.

    Thank you.


    Ricardo Sabino --- http://www.ricardosabino.com


    • Edited by n0n4m3 Monday, March 10, 2014 5:07 AM
    • Merged by Anna Cc Friday, March 28, 2014 12:56 PM same issue
    Monday, March 10, 2014 5:06 AM
  • Hi Ricardo,

    Thank you for posting here!

    This forum is to discuss and ask questions about Visual Studio Extensibility (VSX), using the Extension Manager, building VSIX containers for deployment, the Visual Studio SDK, Text Templates (T4), add-ins, macros, and more.

    According to the information you mentioned above, I’m not clear that what visual studio extension you want to realize.

    I guess there is something wrong with the property DTE.SolutionBuild.StartupProjects. Please check this document "SolutionBuild.StartupProjects Property ".

    Here is the code snippet for your reference.

    public void CodeExample(DTE2 dte)
    {  
        try
        {
            SolutionBuild sb = dte.Solution.SolutionBuild;
            SolutionConfiguration sc = sb.ActiveConfiguration;
            vsBuildState vsBS;
            string msg = "Return relative path to startup projects: ";
            foreach (String s in (Array)sb.StartupProjects)
            {
                msg += "\n   " + s;
            }
            msg += "\nSolutionConfiguration: " + sc.Name;
            vsBS = sb.BuildState;
            if (vsBS == vsBuildState.vsBuildStateDone)
                msg += "\nA build has occurred.";
            else if (vsBS == vsBuildState.vsBuildStateInProgress)
                msg += "\nA build is in progress.";
            else msg += "\nA build has not occurred.";
    
            MessageBox.Show(msg);
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    Best regards,

    Sunny

    Monday, March 10, 2014 8:33 AM
  • Hi Sunny,

    Sorry, I forgot to mention that I'm testing this on VS2012.

    I don't see what can be wrong with: DTE.Solution.SolutionBuild.StartupProjects

    When I assign a string with the name of the project I see it changing in Solution Explorer but for some reason the changes don't persist when I close the solution.


    Ricardo Sabino --- http://www.ricardosabino.com


    • Edited by n0n4m3 Monday, March 10, 2014 1:38 PM
    Monday, March 10, 2014 1:38 PM
  • Hi,

    Could you please tell us what visual studio extension you want to create?

    Best regards,

    Sunny

    Tuesday, March 11, 2014 7:29 AM
  • Hi,

    Please tell us what visual studio extension you want to create. Your more detailed information will be great. 

    Best regards,

    Sunny

    Tuesday, March 11, 2014 7:33 AM
  • Hi,

    The help I need is for this extension:

    http://n0n4m3.codingcorner.net/?p=1056 (new version)

    http://n0n4m3.codingcorner.net/?p=214 (old version)

    Description

    Command Line Arguments Made Easy (CLIArgsMadeEasy) is a Visual Studio Add-in that eases the access and change of the startup project’s command line arguments. Instead of having to go to project properties or instead of using the command window to run your program with different arguments, CLIArgsMadeEasy adds a toolbox for you to add and edit your custom arguments.


    Ricardo Sabino --- http://www.ricardosabino.com | http://www.digiflare.com

    Tuesday, March 11, 2014 2:52 PM
  • Hi,

    The help I need is for this extension:

    http://n0n4m3.codingcorner.net/?p=1056 (new version)

    http://n0n4m3.codingcorner.net/?p=214 (old version)

    Description

    Command Line Arguments Made Easy (CLIArgsMadeEasy) is a Visual Studio Add-in that eases the access and change of the startup project’s command line arguments. Instead of having to go to project properties or instead of using the command window to run your program with different arguments, CLIArgsMadeEasy adds a toolbox for you to add and edit your custom arguments.


    Ricardo Sabino --- http://www.ricardosabino.com | http://www.digiflare.com

    Tuesday, March 11, 2014 2:53 PM
  • Hi Ricardo,

    Thank you for your details!

    I have download CLIArgsMadeEasy2 (for Visual Studio 2012).

    I test it with the steps below.

    I have a solution named "testsolution". After I add a project to testsolution, I find that the new created project will be added to your CLIArgsMadeEasy2. However, if I remove a project form testsolution, the removed project will still in your CLIArgsMadeEasy2.

    >> I know how to detect when a project is removed from the solution

    So I think you need to detect what project has been removed form the solution and remove it form your CLIArgsMadeEasy2. After that, you need to use SolutionBuild::StartupProjects Property to find the start up project. Please keep finding the start up project until it is in the solution (in the case that it has been removed).

    Best regards,

    Sunny


    • Edited by Anna Cc Thursday, March 13, 2014 6:26 AM
    Thursday, March 13, 2014 6:25 AM
  • Thank you Sunny but unfortunately the second part of your answer doesn't work. When I try to look up the SolutionBuild.StartupProjects property it still holds the project we just removed has the startup project. So the startup project change in Visual Studio occurs after removing the current project and thus I have no way of knowing what the next startup project is going to be.

    From my first post:

    "The event argument that is sent when I listen to the project removed event is the current project but if I try to look for the current startup project, it will still be the previous project."


    Ricardo Sabino --- http://www.ricardosabino.com | http://www.digiflare.com


    • Edited by n0n4m3 Thursday, March 13, 2014 1:24 PM
    Thursday, March 13, 2014 1:23 PM
  • Hi,

    Thank you for your feedback!

    Has your problem been solved?

    From the document "SolutionBuild.StartupProjects Property ", we see it can get or set the names of projects that are entry points for the application.

    I guess it may be a time-delay. Have you tried with a loop or set a timer?

    Best regards,

    Sunny

    • Marked as answer by Anna Cc Wednesday, June 25, 2014 11:25 AM
    Tuesday, April 1, 2014 7:57 AM
  • Hi Sunny,

    The timer solves the problem but that is far from the best solution here.

    Thank you,
    Ricardo.


    Ricardo Sabino --- http://www.ricardosabino.com | http://www.digiflare.com

    Monday, April 7, 2014 12:22 PM