0
votes
  1. I added a tool window to VSIX extension using these steps https://docs.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-tool-window?view=vs-2019
  2. When the extension is installed the tool window must open once
  3. But the tool window opens up every time the Visual studio opens.

How to open tool window only when it is required?

These are the attributes am using,

[ProvideToolWindow(typeof(MyWindow), Orientation = ToolWindowOrientation.Left, DocumentLikeTool = true, Style = Microsoft.VisualStudio.Shell.VsDockStyle.Tabbed)]
[ProvideToolWindowVisibility(typeof(MyWindow), VSConstants.UICONTEXT.SolutionExists_string, Name = "Extension Overview")]
1

1 Answers

1
votes

Deepak,

By using VSConstants.UIContext.SolutionExists_string, you are registering the toolwindow to display whenever a solution exists in the VS IDE. If you don't want this behavior, remove the attribute.

Note, Toolwindows are almost always associated with a particular scenario or IDE state (like during debugging, building, or coding). This is typically where you would leverage the ProvideToolWindowVisibility attribute. To associate your toolwindow to a specific activity or state. However, if the user manually closes the toolwindow while in that UI state, the IDE will try to remember that. So that it no longer appear by default while (debugging, building, or coding, etc.). This is what is meant, when the toolwindow layout is described as being "sticky".

If you are curious as to what UI Contexts are currently active in the IDE (to figure out which you'd like your toolwindow to be visible with), I highly recommend using the Component Diagnostics extension, to monitor what UI Contexts are active, during the scenario(s) you want your toolwindow to show up under.