locked
Build/Rebuild Project VS 2008 using DTE RRS feed

  • Question

  • How can I Build and Rebuild a Project csproj using DTE.ExecuteCommand ?

    Any reference of all commands of DTE ?

    For solution, I use this:

    Logica.BuildTracking.IniciarBuildTrack(); 
                        proyecto
    .DTE.ExecuteCommand("Build.RebuildSolution", ""); 
                       
    while (!Logica.BuildTracking.BuildFinalizado) 
                       
    { 
                           
    Application.DoEvents(); 
                           
    //System.Threading.Thread.Sleep(1000); 
                       
    } 

    I need for project csproj, only a project


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Wednesday, December 1, 2010 10:22 PM

Answers

  • This isn't using DTE (my DTE skills aren't terribly strong), it just uses the raw VS services that DTE itself would probably end up using.  I also haven't tested it exhaustively so there may be bugs :)

    /// <summary>
    /// Selects a project in the solution explorer toolwindow based on the name that is displayed for the project in that window.
    /// </summary>
    public class ProjectSelector
    {
      private System.IServiceProvider serviceProvider;
      private Microsoft.VisualStudio.Shell.Interop.IVsSolution solution;
      private Microsoft.VisualStudio.Shell.Interop.IVsUIShell shell;
    
      /// <summary>
      /// Initializes a new instance of the <see cref="ProjectSelector"/> class.
      /// </summary>
      /// <param name="serviceProvider">A <see cref="System.IServiceProvider"/> the class can use to fetch the VS services it needs.</param>
      /// <exception cref="ArgumentNullException">Throws this exception if <paramref name="serviceProvider"/> is null.</exception>
      public ProjectSelector(System.IServiceProvider serviceProvider)
      {
        if (serviceProvider == null)
        {
          throw new ArgumentNullException("serviceProvider");
        }
    
        this.serviceProvider = serviceProvider;
      }
    
      /// <summary>
      /// Selects the project node in the solution explorer whose <see cref="__VSHPROPID.VSHPROPID_Caption"/> property matches <paramref name="projectName"/>.
      /// </summary>
      /// <param name="projectName">The name of the project node to select.</param>
      /// <exception cref="ArgumentNullException">Throws this exception if <paramref name="projectName"/> is null.</exception>
      /// <exception cref="ArgumentException">Throws this exception if <paramref name="projectName"/> is the empty string or consists solely of whitespace, or if we fail to find a project node matching <paramref name="projectName"/>.</exception>
      /// <exception cref="COMException">Throws this for any COM call failures we encounter.</exception>
      public void SelectProjectByName(string projectName)
      {
        if (projectName == null)
        {
          throw new ArgumentNullException("projectName");
        }
    
        if (String.IsNullOrWhiteSpace(projectName))
        {
          throw new ArgumentException("The value given to SelectProjectByName for the parameter 'projectName' is the empty string or consists solely of whitespace.");
        }
    
        //Figure out how many projects we have in the current solution
        uint projectCount = GetProjectCount();
    
        //Okay, now we know that a project with a matching name exists, we just need to find its IVsHierarchy.
        IVsHierarchy hierarchy = FindHierarchyByName(projectName, projectCount);
        if (hierarchy == null)
        {
          throw new ArgumentException(String.Format("Failed to find an IVsHierarchy with the Caption property of '{0}'.", projectName));
        }
    
        //Now we need to get the solution explorer window, and get its associated IVsUIHierarchyWindow so we can programatically
        //tell it to select the IVsUIHierarchy we have found.
        Guid slnExplorerGuid = new Guid(EnvDTE.Constants.vsWindowKindSolutionExplorer);
        IVsWindowFrame windowFrame;
        ErrorHandler.ThrowOnFailure(Shell.FindToolWindow((int)__VSFINDTOOLWIN.FTW_fForceCreate, ref slnExplorerGuid, out windowFrame));
    
        object rawHierarchyWindow;
        ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out rawHierarchyWindow));
        IVsUIHierarchyWindow hierarchyWindow = (IVsUIHierarchyWindow)rawHierarchyWindow;
    
        //Finally tell the hierarchy window to select the UI hierarchy we have found.
        IVsUIHierarchy uiHierarchy = (IVsUIHierarchy)hierarchy;
        ErrorHandler.ThrowOnFailure(hierarchyWindow.ExpandItem(uiHierarchy, (uint)VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem));
      }
    
      /// <summary>
      /// Gets the <see cref="IVsSolution"/> object from Visual Studio.
      /// </summary>
      private IVsSolution Solution
      {
        get
        {
          if (this.solution == null)
          {
            this.solution = (IVsSolution)this.serviceProvider.GetService(typeof(SVsSolution));
          }
    
          return this.solution;
        }
      }
    
      /// <summary>
      /// Gets the <see cref="IVsUIShell"/> object from Visual Studio.
      /// </summary>
      private IVsUIShell Shell
      {
        get
        {
          if (this.shell == null)
          {
            this.shell = (IVsUIShell)this.serviceProvider.GetService(typeof(SVsUIShell));
          }
    
          return this.shell;
        }
      }
    
      /// <summary>
      /// Gets the total count of loaded projects in the current solution.
      /// </summary>
      /// <returns>The total count of loaded projects in the current solution.</returns>
      /// <exception cref="COMException">Throws this for any COM call failures we encounter.</exception>
      private uint GetProjectCount()
      {
        uint projectCount;
        ErrorHandler.ThrowOnFailure(Solution.GetProjectFilesInSolution((uint)__VSGETPROJFILESFLAGS.GPFF_SKIPUNLOADEDPROJECTS,
                                        0 /*arraySize*/,
                                        null /*projectNameArray*/,
                                        out projectCount));
        return projectCount;
      }
    
      /// <summary>
      /// Finds an <see cref="IVsHierarchy"/> whose <see cref="__VSHPROPID.VSHPROPID_Caption"/> property matches <paramref name="projectName"/>.
      /// </summary>
      /// <param name="projectName">The name of the project (as displayed in the solution explorer window) that you want to locate.</param>
      /// <param name="projectCount">The total count of projects in the solution.</param>
      /// <returns>An <see cref="IVsHierarchy"/> whose <see cref="__VSHPROPID.VSHPROPID_Caption"/> property matches <paramref name="projectName"/> or null if one could not be found.</returns>
      /// <exception cref="ArgumentException">Throws this if the hierarchy enumerator returns a number of hierarchies that differs from <paramref name="projectCount"/>.</exception>
      /// <exception cref="COMException">Throws this for any COM call failures we encounter.</exception>
      private IVsHierarchy FindHierarchyByName(string projectName, uint projectCount)
      {
        Guid empty = Guid.Empty;
        IEnumHierarchies hierarchyEnumerator;
        ErrorHandler.ThrowOnFailure(Solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref empty /*ignored*/, out hierarchyEnumerator));
        ErrorHandler.ThrowOnFailure(hierarchyEnumerator.Reset());
    
        IVsHierarchy[] hierarchies = new IVsHierarchy[projectCount];
        uint hierarchiesFetched;
        ErrorHandler.ThrowOnFailure(hierarchyEnumerator.Next((uint)hierarchies.Length, hierarchies, out hierarchiesFetched));
        if (hierarchiesFetched != projectCount)
        {
          throw new ArgumentException(String.Format("Attempted to fetch {0} project from the IEnumHierarchies object but it returned only {1}.",
                               projectCount.ToString(), hierarchiesFetched.ToString()));
        }
    
        foreach (IVsHierarchy hierarchy in hierarchies)
        {
          object caption;
          ErrorHandler.ThrowOnFailure(hierarchy.GetProperty((uint)VSConstants.VSITEMID_ROOT,
                                   (int)__VSHPROPID.VSHPROPID_Caption,
                                   out caption));
    
          string captionAsString = caption as string;
          if ((captionAsString != null) && String.Equals(captionAsString, projectName, StringComparison.OrdinalIgnoreCase))
          {
            return hierarchy;
          }
        }
    
        return null;
      }
    }
    
    

     Its use looks something like this

    System.IServiceProvider serviceProvider; //set this to your IServiceProvider.  You can use Package.GlobalProvider or any other one you may have around.

    ProjectSelector selector = new ProjectSelector(serviceProvider);
    selector.SelectProjectByName("NameOfTheProjectAsItAppearsInSolutionExplorer");

    When SelectProjectByName returns the project node whose display text matches the string you passed in to SelectProjectByName should be selected in the UI, then if you invoke any project specific commands via DTE.ExecuteCommand they will be invoked against that project.

    Ryan

    • Proposed as answer by Victor_Chen Monday, December 13, 2010 2:38 AM
    • Marked as answer by Victor_Chen Monday, December 27, 2010 9:55 AM
    Saturday, December 11, 2010 8:25 PM

All replies

  • Hi Alhambra,

     

    Thanks for your post.

    I think you can try to execute command

    "Build.RebuildOnlyProject"

    "Build.RebuildSelection"

    "Build.RebuildSolution"

    with DTE.ExecuteCommand("")

    Hope this can help.

     

    Best Regards,

    Ziwei Chen

     

     

     

     


    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.
    Friday, December 3, 2010 7:24 AM
  • I try it and I get this errors:

     

    //"Build.BuildOnlyProject" not available

    //"Build.RebuildOnlyProject" not available


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Friday, December 3, 2010 9:17 AM
  • Hi Alhambra,

     

    Thanks for your rapid feedback.

    In order for Build.BuildOnlyProject to work properly, the selection in the Solution Explorer window must be a project (or be a sub-node of a project). If you select the solution root node, you'll notice that the Build menu no longer contains the "Project Only" submenu that contains a map to Build.BuildOnlyProject. If you select a project in the Solution Explorer, you'll find that both your keybinding and the Build menu are now active. If it is not what you expected, please try

    "Build.BuildSelection"

    For more information, please check

    http://connect.microsoft.com/VisualStudio/feedback/details/224080/unable-to-assign-a-keystroke-to-build-buildonlyproject

     

    Hope this helps.

     

    Best Regards,

    Ziwei Chen

     


    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.
    Friday, December 3, 2010 9:39 AM
  • I want do all programatically,

    I have Solution2 solucion and  Project proyecto variables in method in my Addin.

     

    I do this:

      EnvDTE80.SolutionBuild2 solutionBuild2 =   (EnvDTE80.SolutionBuild2)solucion.SolutionBuild;

     var configurationName = proyecto.ConfigurationManager.ActiveConfiguration.ConfigurationName;

      solutionBuild2.BuildProject(configurationName, proyecto.FullName, true);

                        bool compiledOK = (solutionBuild2.LastBuildInfo == 0);

                        if (solutionBuild2.BuildState == vsBuildState.vsBuildStateDone)

                        {

     

                        }

    How can I select a project in the Solution Explorer, programatically ??

    Thanks !! 

     


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Friday, December 3, 2010 9:52 AM
  • Hi Alhambra,

     

    Thanks for your post.

    To select a project programmatically, I think you can try

    DTE.ActiveWindow.Object.GetItem("Solution\Project").Select(vsUISelectionType.vsUISelectionTypeSelect)

    If it doesn't help, be free to let me know

     

    Best Regards,

    Ziwei Chen


    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.
    Monday, December 6, 2010 2:42 AM
  • Hi Alhambra,

     

     

     

    Is it resolved?

    Best Regards,

    Ziwei Chen

     


    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.
    Wednesday, December 8, 2010 8:53 AM
  • I cannot test it yet, I hope test soon.Thanks !!!
    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Wednesday, December 8, 2010 11:38 AM
  • Hi Alhambra,

     

    Thanks for your feedback.

    I'm going to close this thread, if my solution doesn't help, be free to unmark it anytime.

     

    Best Regards,

    Ziwei Chen


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 10, 2010 9:00 AM
  • I use C#,

    proyecto is Project

     

     // TODO RebuildOnlyProject!!!

                        proyecto.DTE.ActiveWindow.Object.GetItem(solutionName + @"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect); <========= NOT compiles

                        proyecto.DTE.ExecuteCommand("Build.RebuildOnlyProject", "");

     

    Object hasn't GetItem method, is a object only...

     

    this code only is for Macros:

    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate();

    DTE.ActiveWindow.Object.GetItem(solutionName + @"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect);

     

    It's difficult progrraming DTE, extensibility VS...

     

     


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Friday, December 10, 2010 1:35 PM
  • This isn't using DTE (my DTE skills aren't terribly strong), it just uses the raw VS services that DTE itself would probably end up using.  I also haven't tested it exhaustively so there may be bugs :)

    /// <summary>
    /// Selects a project in the solution explorer toolwindow based on the name that is displayed for the project in that window.
    /// </summary>
    public class ProjectSelector
    {
      private System.IServiceProvider serviceProvider;
      private Microsoft.VisualStudio.Shell.Interop.IVsSolution solution;
      private Microsoft.VisualStudio.Shell.Interop.IVsUIShell shell;
    
      /// <summary>
      /// Initializes a new instance of the <see cref="ProjectSelector"/> class.
      /// </summary>
      /// <param name="serviceProvider">A <see cref="System.IServiceProvider"/> the class can use to fetch the VS services it needs.</param>
      /// <exception cref="ArgumentNullException">Throws this exception if <paramref name="serviceProvider"/> is null.</exception>
      public ProjectSelector(System.IServiceProvider serviceProvider)
      {
        if (serviceProvider == null)
        {
          throw new ArgumentNullException("serviceProvider");
        }
    
        this.serviceProvider = serviceProvider;
      }
    
      /// <summary>
      /// Selects the project node in the solution explorer whose <see cref="__VSHPROPID.VSHPROPID_Caption"/> property matches <paramref name="projectName"/>.
      /// </summary>
      /// <param name="projectName">The name of the project node to select.</param>
      /// <exception cref="ArgumentNullException">Throws this exception if <paramref name="projectName"/> is null.</exception>
      /// <exception cref="ArgumentException">Throws this exception if <paramref name="projectName"/> is the empty string or consists solely of whitespace, or if we fail to find a project node matching <paramref name="projectName"/>.</exception>
      /// <exception cref="COMException">Throws this for any COM call failures we encounter.</exception>
      public void SelectProjectByName(string projectName)
      {
        if (projectName == null)
        {
          throw new ArgumentNullException("projectName");
        }
    
        if (String.IsNullOrWhiteSpace(projectName))
        {
          throw new ArgumentException("The value given to SelectProjectByName for the parameter 'projectName' is the empty string or consists solely of whitespace.");
        }
    
        //Figure out how many projects we have in the current solution
        uint projectCount = GetProjectCount();
    
        //Okay, now we know that a project with a matching name exists, we just need to find its IVsHierarchy.
        IVsHierarchy hierarchy = FindHierarchyByName(projectName, projectCount);
        if (hierarchy == null)
        {
          throw new ArgumentException(String.Format("Failed to find an IVsHierarchy with the Caption property of '{0}'.", projectName));
        }
    
        //Now we need to get the solution explorer window, and get its associated IVsUIHierarchyWindow so we can programatically
        //tell it to select the IVsUIHierarchy we have found.
        Guid slnExplorerGuid = new Guid(EnvDTE.Constants.vsWindowKindSolutionExplorer);
        IVsWindowFrame windowFrame;
        ErrorHandler.ThrowOnFailure(Shell.FindToolWindow((int)__VSFINDTOOLWIN.FTW_fForceCreate, ref slnExplorerGuid, out windowFrame));
    
        object rawHierarchyWindow;
        ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out rawHierarchyWindow));
        IVsUIHierarchyWindow hierarchyWindow = (IVsUIHierarchyWindow)rawHierarchyWindow;
    
        //Finally tell the hierarchy window to select the UI hierarchy we have found.
        IVsUIHierarchy uiHierarchy = (IVsUIHierarchy)hierarchy;
        ErrorHandler.ThrowOnFailure(hierarchyWindow.ExpandItem(uiHierarchy, (uint)VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem));
      }
    
      /// <summary>
      /// Gets the <see cref="IVsSolution"/> object from Visual Studio.
      /// </summary>
      private IVsSolution Solution
      {
        get
        {
          if (this.solution == null)
          {
            this.solution = (IVsSolution)this.serviceProvider.GetService(typeof(SVsSolution));
          }
    
          return this.solution;
        }
      }
    
      /// <summary>
      /// Gets the <see cref="IVsUIShell"/> object from Visual Studio.
      /// </summary>
      private IVsUIShell Shell
      {
        get
        {
          if (this.shell == null)
          {
            this.shell = (IVsUIShell)this.serviceProvider.GetService(typeof(SVsUIShell));
          }
    
          return this.shell;
        }
      }
    
      /// <summary>
      /// Gets the total count of loaded projects in the current solution.
      /// </summary>
      /// <returns>The total count of loaded projects in the current solution.</returns>
      /// <exception cref="COMException">Throws this for any COM call failures we encounter.</exception>
      private uint GetProjectCount()
      {
        uint projectCount;
        ErrorHandler.ThrowOnFailure(Solution.GetProjectFilesInSolution((uint)__VSGETPROJFILESFLAGS.GPFF_SKIPUNLOADEDPROJECTS,
                                        0 /*arraySize*/,
                                        null /*projectNameArray*/,
                                        out projectCount));
        return projectCount;
      }
    
      /// <summary>
      /// Finds an <see cref="IVsHierarchy"/> whose <see cref="__VSHPROPID.VSHPROPID_Caption"/> property matches <paramref name="projectName"/>.
      /// </summary>
      /// <param name="projectName">The name of the project (as displayed in the solution explorer window) that you want to locate.</param>
      /// <param name="projectCount">The total count of projects in the solution.</param>
      /// <returns>An <see cref="IVsHierarchy"/> whose <see cref="__VSHPROPID.VSHPROPID_Caption"/> property matches <paramref name="projectName"/> or null if one could not be found.</returns>
      /// <exception cref="ArgumentException">Throws this if the hierarchy enumerator returns a number of hierarchies that differs from <paramref name="projectCount"/>.</exception>
      /// <exception cref="COMException">Throws this for any COM call failures we encounter.</exception>
      private IVsHierarchy FindHierarchyByName(string projectName, uint projectCount)
      {
        Guid empty = Guid.Empty;
        IEnumHierarchies hierarchyEnumerator;
        ErrorHandler.ThrowOnFailure(Solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref empty /*ignored*/, out hierarchyEnumerator));
        ErrorHandler.ThrowOnFailure(hierarchyEnumerator.Reset());
    
        IVsHierarchy[] hierarchies = new IVsHierarchy[projectCount];
        uint hierarchiesFetched;
        ErrorHandler.ThrowOnFailure(hierarchyEnumerator.Next((uint)hierarchies.Length, hierarchies, out hierarchiesFetched));
        if (hierarchiesFetched != projectCount)
        {
          throw new ArgumentException(String.Format("Attempted to fetch {0} project from the IEnumHierarchies object but it returned only {1}.",
                               projectCount.ToString(), hierarchiesFetched.ToString()));
        }
    
        foreach (IVsHierarchy hierarchy in hierarchies)
        {
          object caption;
          ErrorHandler.ThrowOnFailure(hierarchy.GetProperty((uint)VSConstants.VSITEMID_ROOT,
                                   (int)__VSHPROPID.VSHPROPID_Caption,
                                   out caption));
    
          string captionAsString = caption as string;
          if ((captionAsString != null) && String.Equals(captionAsString, projectName, StringComparison.OrdinalIgnoreCase))
          {
            return hierarchy;
          }
        }
    
        return null;
      }
    }
    
    

     Its use looks something like this

    System.IServiceProvider serviceProvider; //set this to your IServiceProvider.  You can use Package.GlobalProvider or any other one you may have around.

    ProjectSelector selector = new ProjectSelector(serviceProvider);
    selector.SelectProjectByName("NameOfTheProjectAsItAppearsInSolutionExplorer");

    When SelectProjectByName returns the project node whose display text matches the string you passed in to SelectProjectByName should be selected in the UI, then if you invoke any project specific commands via DTE.ExecuteCommand they will be invoked against that project.

    Ryan

    • Proposed as answer by Victor_Chen Monday, December 13, 2010 2:38 AM
    • Marked as answer by Victor_Chen Monday, December 27, 2010 9:55 AM
    Saturday, December 11, 2010 8:25 PM
  • Thanks, much thx

    now, how I can get the System.IServiceProvider  ?? My code is executed by Addind ( I have DTE object).

     

    solution:  IServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(proyecto.DTE as

        Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

     

    Now, I get this error:

    Failed to find an IVsHierarchy with the Caption property of 'Prueba001\ProyectoConDML1'.

     

    Change to "ProyectoConDML1", and now all work.

     

    my code is:

     

     

     

    IServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(proyecto.DTE as
    
        Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
    
    
    
                var selector = new ProjectSelector(serviceProvider);
    
    
    
                string solutionFile = solucion.FileName;
    
                string solutionName = System.IO.Path.GetFileNameWithoutExtension(solutionFile);
    
                string projectName = System.IO.Path.GetFileNameWithoutExtension(proyecto.FileName);
    
    
    
                selector.SelectProjectByName(projectName);

     

    The solutionName is 'Prueba001 and project is ProyectoConDML1, is correct.


    I try this command after, but I get errors that it is not available .


    try
                    {
                        proyecto.DTE.ExecuteCommand("Build.BuildOnlyProject", ""); // not available
                    }
                    catch (Exception ex)
                    {
    
                    }
    
                    try
                    {
                        proyecto.DTE.ExecuteCommand("Build.RebuildSelection", ""); // not available
                    }
                    catch (Exception ex)
                    {
    
                    }
    
    
                    try
                    {
                        solucion.DTE.ExecuteCommand("Build.RebuildSelection", ""); // not available
                    }
                    catch (Exception ex)
                    {
    
                    }
    


    any suggestions

     

    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Wednesday, December 22, 2010 10:08 AM
  • new Microsoft.VisualStudio.Shell.ServiceProvider(proyecto.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider)

    should do the trick (after adding a reference to Microsoft.VisualStudio.Shell.<some version here>.dll to your project).

    Ryan

    Wednesday, December 22, 2010 9:25 PM
  • Also, as the helper class was written it looks only at the 'leaf' name, i.e. it is looking for the name exactly as it appears in the UI, which probably isn't 'Prueba001\ProyectoConDML1', it is probably ProyectoConDML1, which is why changing it to that works (I assume Prueba001 is the solution name here?)

    Ryan

    Wednesday, December 22, 2010 9:27 PM
  • Yes, 

    the solutionName is 'Prueba001 and project is ProyectoConDML1 .

     selector.SelectProjectByName(projectName); is CORRECT, all right

     

    the problem is this commands: I try this command after, but I get errors that it is not available .



                        proyecto.DTE.ExecuteCommand("Build.BuildOnlyProject", ""); // not available
                        proyecto.DTE.ExecuteCommand("Build.RebuildSelection", ""); // not available
                        solucion.DTE.ExecuteCommand("Build.RebuildSelection", ""); // not available
    
    
    thx


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Wednesday, December 22, 2010 9:36 PM
  • And if you manually select the node in the solution explorer are those commands available?  And the node is showing as selected in the solution explorer when you call DTE.ExecuteCommand?

    Ryan

    Wednesday, December 22, 2010 10:44 PM
  • If select project,

     

     

     private static void PruebasCompilarSoloProyecto(Solution2 solucion, Project proyecto)
    
            {
    
    
    
                try
    
                {
    
                    //System.IServiceProvider serviceProvider; //set this to your IServiceProvider.  You can use Package.GlobalProvider or any other one you may have around.
    
                    IServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(proyecto.DTE as
    
            Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
    
    
    
                    var selector = new ProjectSelector(serviceProvider);
    
    
    
                    string solutionFile = solucion.FileName;
    
                    string solutionName = System.IO.Path.GetFileNameWithoutExtension(solutionFile);
    
                    string projectName = System.IO.Path.GetFileNameWithoutExtension(proyecto.FileName);
    
    
    
                    selector.SelectProjectByName(projectName);
    
    
    
    

     

    then

          proyecto.DTE.ExecuteCommand("Build.RebuildSelection", ""); 

    is OK.


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Thursday, January 13, 2011 10:25 AM
  • And without manually selecting it if you just run the ProjectSelector code does the node appear selected in the UI?


    Ryan

    Friday, January 14, 2011 4:11 PM