In the VS 2017 user project system, how can I make a project element bold in Solution Explorer?

I am writing a project system extension for VS 2017, and each project in my language has one file, which is a β€œboot file”. I want this file to appear in bold in Solution Explorer.

Python Tools for VS does what I'm looking for, but my extension is built on a new project system structure (CPS). The CPS way to change the appearance of Solution Explorer elements is to implement IProjectTreePropertiesProvider , but I don't see any way to change the text style with it - only icons.

+5
source share
1 answer

I'm not sure if CPS has something for this, but you can still use a combination of the "old" native / managed Visual Studio interfaces. This is an example that uses IProjectTreePropertiesProvider:

 [Export(typeof(IProjectTreePropertiesProvider))] [AppliesTo(MyUnconfiguredProject.UniqueCapability)] [Order(1000)] internal class ProjectTreePropertiesProvider1 : IProjectTreePropertiesProvider { // we need to import that to do COM calls [Import] protected IProjectThreadingService ThreadingService { get; set; } // we want the "old" IVsHierarchy interface [ImportMany(ExportContractNames.VsTypes.IVsHierarchy)] private OrderPrecedenceImportCollection<IVsHierarchy> IVsHierarchies { get; } private IVsHierarchy VsHierarchy => IVsHierarchies.First().Value; [ImportingConstructor] public ProjectTreePropertiesProvider1(UnconfiguredProject unconfiguredProject) { IVsHierarchies = new OrderPrecedenceImportCollection<IVsHierarchy>(projectCapabilityCheckProvider: unconfiguredProject); } /// <summary> /// Calculates new property values for each node in the project tree. /// </summary> /// <param name="propertyContext">Context information that can be used for the calculation.</param> /// <param name="propertyValues">Values calculated so far for the current node by lower priority tree properties providers.</param> public async void CalculatePropertyValues(IProjectTreeCustomizablePropertyContext propertyContext, IProjectTreeCustomizablePropertyValues propertyValues) { // this is from the standard WindowsScript project type sample if (propertyValues.Flags.Contains(ProjectTreeFlags.Common.ProjectRoot)) { // etc.. propertyValues.Icon = KnownMonikers.JSProjectNode.ToProjectSystemType(); // etc.. } // now, we're doing some COM calls, ensure it happens on UI thread await ThreadingService.SwitchToUIThread(); // get the id of some item (this "Start.js" item is from the standard sample) VsHierarchy.ParseCanonicalName("Start.js", out uint id); // get IVsUIShell from service provider VsHierarchy.GetSite(out Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp); var shell = (IVsUIShell)sp.QueryService<IVsUIShell>(); // get solution explorer window var SolutionExplorer = new Guid(ToolWindowGuids80.SolutionExplorer); shell.FindToolWindow(0, ref SolutionExplorer, out IVsWindowFrame frame); // get solution explorer DocView frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out object obj); var window = (IVsUIHierarchyWindow2)obj; // change attribute of the item window.SetItemAttribute((IVsUIHierarchy)VsHierarchy, id, (uint)__VSHIERITEMATTRIBUTE.VSHIERITEMATTRIBUTE_Bold, true); } } 
+4
source

Source: https://habr.com/ru/post/1270216/


All Articles