1
我正在編寫一個c#控制檯應用程序envdte/envdte80(沒有經驗)打開一個新的Visual Studio實例內的項目。在這個新實例中,我試圖通過我的控制檯應用程序更改Project.StartOptions。envdte configurationmanager項目StartOptions
當我嘗試加載ConfigurationManager時,我收到以下異常: 「System.InvalidOperationException」, 「由於對象的當前狀態,操作無效」。
我的代碼:
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";
...
}
...
}
...
}
}
}