1

J'écris une application de console C# avec envdte/envdte80 (aucune expérience avec les deux) pour ouvrir un projet dans une nouvelle instance de Visual Studio. Dans cette nouvelle instance, j'essaie de modifier Project.StartOptions via mon application de console.envdte configurationmanager Project StartOptions

Lorsque je tente de charger le ConfigurationManager, je reçois cette exception: « System.InvalidOperationException », « Le fonctionnement est pas valide en raison de l'état actuel de l'objet. »

Mon code:

using EnvDTE; 
using EnvDTE80; 
using System; 

namespace AutomationProject 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      ... 
      EnvDTE80.DTE2 dte; 
      object obj = null; 
      System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.14.0", true); 
      System.Threading.Thread.Sleep(1000); 
      // Attempt to create an instance of envDTE. 
      obj = System.Activator.CreateInstance(t, true); 

      // Cast to DTE2. 
      dte = (EnvDTE80.DTE2)obj; 
      dte.MainWindow.Visible = true; 
      //dte.MainWindow.Activate(); 
      //dte.UserControl = true; 
      dte.ExecuteCommand("File.OpenProject", projectLocation + projectName); 

      //dte.ExecuteCommand("Project.StartOptions", "-break -lib:ModuleName -exec:TestName"); 
      // Get a reference to the solution2 object. 
      System.Threading.Thread.Sleep(1000); 
      Solution2 soln = (Solution2)dte.Solution; 
      Project proj = soln.Projects.Item(1); 
      try 
      { 
       dte.Solution.SolutionBuild.SolutionConfigurations.Item(1).Activate(); 
       ConfigurationManager configmgr; 
       Configuration config; 
       if (dte.Solution.Projects.Count > 0) 
       { 
        configmgr = dte.Solution.Projects.Item(1).ConfigurationManager; 
        config = proj.ConfigurationManager.ActiveConfiguration; 
        config.Properties.Item("StartArguments").Value = "command line arguments"; 
       ... 
       } 
      ... 
      } 
     ... 
     } 
    } 
} 

Répondre

0

[RESOLU] Projet

était un exécutable, ce fut la raison pour laquelle il ne peut pas initialiser un ConfigurationManager.