【发布时间】:2019-07-25 09:16:36
【问题描述】:
我需要什么
我想在 Visual Studio 扩展中获取项目的程序集名称。
因为我知道您可以在解决方案资源管理器中右键单击项目并选择Properties 时看到它。它将在标签Application 中显示Assemblyname。
设置
我的扩展项目中有一个“命令”,当您右键单击解决方案资源管理器中的某些内容时会显示该命令。只要有人点击该命令,就会执行以下代码:
var dte = await GetDTE2Async();
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var selectedItem = GetSelectedItem(dte);
var props = selectedItem.ContainingProject.Properties;
//I just assumed that the `AssemblyName` could be somewhere in the `Properties` Property.
GetSelectedItem 方法如下所示:
public static ProjectItem GetSelectedItem(DTE2 dte)
{
ThreadHelper.ThrowIfNotOnUIThread();
var items = (Array)dte.ToolWindows.SolutionExplorer.SelectedItems;
return items.Cast<UIHierarchyItem>().FirstOrDefault().Object as ProjectItem;
}
【问题讨论】:
标签: c# visual-studio .net-assembly visual-studio-extensions visual-studio-2019