环境配置管理器项目启动选项
envdte configurationmanager Project StartOptions
我正在使用 envdte / envdte80(两者都没有经验)编写一个 c# 控制台应用程序,以在新的 Visual Studio 实例中打开一个项目。在这个新实例中,我试图通过我的控制台应用程序更改 Project.StartOptions。
当我尝试加载 ConfigurationManager 时,我收到此异常:
"System.InvalidOperationException",
"Operation is not valid due to the current state of the object."
我的代码:
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";
...
}
...
}
...
}
}
}
[已解决]
项目是一个可执行文件,这就是它无法初始化 ConfigurationManager 的原因。
我正在使用 envdte / envdte80(两者都没有经验)编写一个 c# 控制台应用程序,以在新的 Visual Studio 实例中打开一个项目。在这个新实例中,我试图通过我的控制台应用程序更改 Project.StartOptions。
当我尝试加载 ConfigurationManager 时,我收到此异常: "System.InvalidOperationException", "Operation is not valid due to the current state of the object."
我的代码:
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";
...
}
...
}
...
}
}
}
[已解决]
项目是一个可执行文件,这就是它无法初始化 ConfigurationManager 的原因。