C# 设计环境中的AppConfig
试图从调试环境中获取组件的appconfig路径,但在构建解决方案vs2017时,我不断从中获取null错误。谢谢你的帮助C# 设计环境中的AppConfig,c#,app-config,C#,App Config,试图从调试环境中获取组件的appconfig路径,但在构建解决方案vs2017时,我不断从中获取null错误。谢谢你的帮助 public string GetAppConfigPath() { var devenv = (DTE)_c.Site.GetService(typeof(DTE)); var projects = (Array)devenv.ActiveSolutionProjects; var activeProj
public string GetAppConfigPath()
{
var devenv = (DTE)_c.Site.GetService(typeof(DTE));
var projects = (Array)devenv.ActiveSolutionProjects;
var activeProject = (Project)projects.GetValue(0);
foreach (ProjectItem item in activeProject.ProjectItems)
{
if (!item.Name.Equals("app.config")) continue;
var info = new System.IO.FileInfo(activeProject.FullName);
if (info.Directory != null)
return info.Directory.FullName + "\\" + item.Name;
}
return null;
}
实际上,我从数组
(Project)projects.GetValue(0)中得到一个索引超出范围的异常代码>-尝试使用GetValue(1)
-COM中的某些集合是基于1而不是基于0的。但请发布整个异常详细信息,特别是堆栈跟踪,并指出异常的行号。提示:此处应使用不区分大小写的字符串比较:item.Name.Equals(“app.config”)
trued 1,没用。。。错误发生在那条线上。这是一个VS错误,只是一个消息框显示错误时,建设,不能复制它。表示Ststem.indexootfrangeexceptions。索引在System.array.InternalGetReference(。。。