- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经使用 EnvDTE 列出了我的解决方案中的所有项目,但我在我的代码中发现了一个错误:我无法获取已卸载的项目。
我找到了一种跳过卸载项目的方法:
if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, project.Kind, System.StringComparison.OrdinalIgnoreCase) == 0)
continue;
这样,我的代码不会崩溃 - 但我无法通过代码加载丢失的项目,因为它们已经存在。
如何将卸载的项目加载到解决方案中?
我试过:
project.DTE.ExecuteCommand("Project.ReloadProject");
出现错误:
System.Runtime.InteropServices.COMException (...): 命令“Project.ReloadProject”不可用。
所以我试图以某种方式得到
application.DTE.ExecuteCommand("Project.ReloadProject");
但在此之前,从我在 NET 上搜索的每个地方,我必须预先选择解决方案中的项目 - 为此,我需要 project.Name
(我有),并且路径,我不知道(我发现的每个示例都假定解决方案路径与项目路径相同,这在一般情况下极不可能)。
最佳答案
Visual Studio SDK 显然是执行此操作的方法。
var dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchyWindow hierarchy;
ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte);
IVsSolution sol = (IVsSolution)sp.GetService(typeof(SVsSolution));
foreach (ProjInfo info in GetProjectInfo(sol))
{
info.Dump();
}
//from http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/60fdd7b4-2247-4c18-b1da-301390edabf3/
static IEnumerable<ProjInfo> GetProjectInfo(IVsSolution sol)
{
Guid ignored = Guid.Empty;
IEnumHierarchies hierEnum;
if (ErrorHandler.Failed(sol.GetProjectEnum((int)__VSENUMPROJFLAGS.EPF_ALLPROJECTS, ref ignored, out hierEnum)))
{
yield break;
}
IVsHierarchy[] hier = new IVsHierarchy[1];
uint fetched;
while ((hierEnum.Next((uint)hier.Length, hier, out fetched) == VSConstants.S_OK) && (fetched == hier.Length))
{
int res = (int)VSConstants.S_OK;
Guid projGuid;
if (ErrorHandler.Failed(res = sol.GetGuidOfProject(hier[0], out projGuid)))
{
Debug.Fail(String.Format("IVsolution::GetGuidOfProject returned 0x{0:X}.", res));
continue;
}
string uniqueName;
if (ErrorHandler.Failed(res = sol.GetUniqueNameOfProject(hier[0], out uniqueName)))
{
Debug.Fail(String.Format("IVsolution::GetUniqueNameOfProject returned 0x{0:X}.", res));
continue;
}
if( System.IO.Path.GetInvalidPathChars().Any (p =>uniqueName.Contains(p) ))
{
uniqueName.Dump("invalid filename found");
yield return new ProjInfo(projGuid,uniqueName);
}
else {
yield return new ProjInfo(projGuid, Path.GetFileName(uniqueName).BeforeOrSelf("{"));
}
}
}
大部分来自 http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/60fdd7b4-2247-4c18-b1da-301390edabf3/
关于c# - 在 EnvDTE 中重新加载卸载的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13770409/
我有一个当前遵循的 Vs2010 包 EnvDTE=>Solution=>Projects=>CodeModel=>CodeElements 递归地执行以下操作并找到类 var q = element
作为 NuGet 安装的一部分,我们需要在安装完成时打开一个网页。 我们的要求是: 如果网页尚未在另一个窗口中打开,请在新窗口中的 Visual Studio 中打开该网页。 自己打开网页很简单: .
我在 Visual Studio 2012 上使用 C# 编写了一个 Visual Studio 向导模板。 我遵循了 MSDN 的步骤:我创建了一个 VS 模板,然后我创建了一个带有实现 IWiza
在 VS 解决方案中有以下结构: 现在,我想获取对“Catalogs”文件夹的引用并将其存储在变量中: //Solution_Name // Configurat
我试图通过 Powershell (envdte) 创建一个带有嵌套解决方案文件夹的 Visual Studio 解决方案。一切都工作到 1 级深,但嵌套解决方案文件夹似乎不起作用(接口(interf
是否可以使用 EnvDTE在非扩展项目(例如类库项目)中组装? 如果是这样,我将如何访问 the ConfigurationManager.ActiveConfiguration property ?
我一直在关注 MSDN's Hello World guide to developing Visual Studio extensions (本文专门讨论如何将其创建为 Visual Studio
我试图在事件文档中找到一个函数,但是我遇到了一个问题,当函数在命名空间内时,我的代码试图获取 EnvDTE.CodeNamespace 对象的成员,但它返回空,我也尝试过 Children,但它也是空
我想使用 ENVDTE 添加对项目的服务引用。唯一的方法是通过以下命令弹出添加服务引用窗口: _applicationObject.ExecuteCommand("Project.AddService
代码语句是指最小的独立代码元素。是否有一个接口(interface)可以以结构化形式获取 EnvDTE.CodeFunction 体内的代码语句。 有一些方法可以将 EnvDTE.CodeFuncti
需要将项目从Solution 移动到SolutionFolder。我正在尝试从解决方案中删除项目并使用 EnvDTE SolutionFolder.AddFromFile(Filepath line)
我已经创建了一个 Visual Studio 加载项,可以将表单添加到打开的解决方案中的现有项目。 这是我创建表单的方式: string templatePath = sol.GetProjectIt
我已经使用 EnvDTE 列出了我的解决方案中的所有项目,但我在我的代码中发现了一个错误:我无法获取已卸载的项目。 我找到了一种跳过卸载项目的方法: if (string.Compare(EnvDTE
我在使用 EnvDTE 创建一种方法来列出我的项目中的所有类时遇到问题,以便使用 T4(基于命名约定)对接口(interface)进行模板化,并且那里的文档似乎都没有描述怎么做。我开始于:
我正在编写一些设计时代码。我想使用这个片段:(找到 here) var dte = (EnvDTE.DTE) GetService(typeof(EnvDTE.DTE)); if (dte != nu
我在 PowerShell 脚本中使用 EnvDTE 来自动化 Visual Studio 2010。这是我使用的代码片段: [void][System.Reflection.Assembly]::L
我使用以下代码将新的 json 文本分配给文档: public virtual async Task SetDocumentText(FileInfo fileInfo, string con
我正在努力跟上 T4 模板的速度。我找到了以下示例 ( here): EnvDTE 命名空间中的任何类型都无法识别。我正在使用 Visual T4 扩展。所有 EnvDTE 类型都带有红色
我正在使用 EnvDTE 在我的最新项目中生成一些代码。 我有一个给定 C# 类的代码类对象的引用,但现在我想遍历它的所有成员(在 codeClass.Members 中)并检查它们的类型。 但是,我
我正在创建一个脚手架工具,并希望通过 EnvDTE 扩展在某个项目中安装 nuget 包。这可能吗? 最佳答案 是的。使用 Invoking NuGet Services from inside Vi
我是一名优秀的程序员,十分优秀!