VS插件开发如何获得解决方案资源管理器的当前项文件相关信息
VS插件开发如何获得解决方案资源管理器的当前项文件相关信息

我们想知道侧栏的当前选中,用以进行一些设置,如将 *.cs 转为 *.ts 定义等等,应该怎么办呢?
可以看看这个:
单独的命令行需要引入这个库 envdte80 https://www.nuget.org/packages/envdte80:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualBasic;
namespace VCmdTest
{
internal class Program
{
static void Main(string[] args)
{
var DTE = Marshal.GetActiveObject("VisualStudio.DTE") as EnvDTE80.DTE2;
var toolWindow = DTE.ToolWindows;
var solutionExplorer = toolWindow.SolutionExplorer;
var selectedItems = (solutionExplorer.SelectedItems as IEnumerable).OfType<UIHierarchyItem>();
foreach (var selectedItem in selectedItems)
{
Console.WriteLine(selectedItem.Name);
}
Console.ReadKey();
//System.Diagnostics.Process.Start(Environment.GetFolderPath( Environment.SpecialFolder.Desktop));
}
}
}
结果如下:


浙公网安备 33010602011771号