[英]envdte configurationmanager Project StartOptions
我正在使用envdte / envdte80(沒有兩者的經驗)編寫ac#console應用程序來在新的Visual Studio實例中打開一個項目。 在這個新實例中,我正在嘗試通過我的控制台應用程序更改Project.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";
...
}
...
}
...
}
}
}
[解決了]
Project是一個可執行文件,這就是它無法初始化ConfigurationManager的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.