You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/extensibility/visualstudio.extensibility/inside-the-sdk/activation-constraints.md
+14-35Lines changed: 14 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -25,13 +25,13 @@ Multiple activation constraints can be combined together using the [`And`](/dotn
25
25
In the following example, the command configuration property `EnabledWhen` defines when the command is in the enabled state. The `ClientContext` method is one of the activation constraint factory methods. It generates the activation constraint, given the two arguments, a string and regular expression pattern to match against that string. Therefore, the following code indicates that a command is enabled when the user has selected a file with one of those extensions.
The `ClientContextKey` class provides the range of IDE state information that you can test against; for a table of values, see [Client context keys](#client-context-keys).
34
+
The [`ClientContextKey`](/dotnet/api/microsoft.visualstudio.extensibility.clientcontextkey) class provides the range of IDE state information that you can test against; for a table of values, see [Client context keys](#client-context-keys).
35
35
36
36
The following example shows how to combine multiple constraints:
37
37
@@ -51,67 +51,46 @@ EnabledWhen =
51
51
52
52
## Activation constraint properties
53
53
54
-
Currently, what you can control with activation constraints is the loading of an extension, and the enabled or visible state of a command. The configuration types contain property of type `ActivationConstraint`, typically with a `When` suffix that implies that something activates when the specified conditions are satisfied. The following properties are of type `ActivationConstraint`:
55
-
56
-
| Property | Description |
57
-
| - | - |
58
-
|`ExtensionConfiguration.LoadedWhen`| Controls when is the extension loaded. |
59
-
|`CommandConfiguration.EnabledWhen`| Controls when the command is enabled (becomes callable). A command that isn't enabled might appear as a grayed out UI item. |
60
-
|`CommandConfiguration.VisibleWhen`| Controls when a command is visible in the IDE. For example, when the menu item or command button appears in the UI. |
54
+
Activation constraints can be used to configure a variety of VisualStudio.Extensibility functionalities, including the [loading of an extension](/dotnet/api/microsoft.visualstudio.extensibility.extensionconfiguration.loadedwhen), and the [enabled](/dotnet/api/microsoft.visualstudio.extensibility.commands.commandconfiguration.enabledwhen) or [visible](/dotnet/api/microsoft.visualstudio.extensibility.commands.commandconfiguration.visiblewhen) state of a command. The configuration types contain property of type `ActivationConstraint`, typically with a `When` suffix that implies that something activates when the specified conditions are satisfied.
61
55
62
56
## Activation constraint factory methods
63
57
64
58
This section shows the list of currently supported activation constraints. Each entry on the list is a factory method on the `ActivationConstraint` type.
65
59
66
60
| Term | Description |
67
61
| -- | -- |
68
-
|[`SolutionHasProjectCapability`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.solutionhasprojectcapability)(\<expression>=[`ProjectCapability`](/dotnet/api/microsoft.visualstudio.extensibility.projectcapability)| True whenever solution has a project with capabilities matching the provided subexpression. An expression can be something like `VB | CSharp`. For more about project capabilities, see [Project query API overview](../project/project.md). |
69
-
|[`SolutionState`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.solutionstate)(\<state>=[`SolutionState`](/dotnet/api/microsoft.visualstudio.extensibility.solutionstate)| True when solution state matches the provided value, see [solution states](#solution-states) for list of values. |
70
-
|[`ProjectAddedItem`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.projectaddeditem)(\<pattern>=\<regex>) | The term is true when a file matching the "pattern" is added to a project in the solution that is opened. |
71
62
|[`ClientContext`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.clientcontext)(\<key>=[`ClientContextKey`](/dotnet/api/microsoft.visualstudio.extensibility.clientcontextkey), \<pattern>=\<regex>) | True when the provided client context key matches to regular expression. See [client context keys](#client-context-keys). |
63
+
|[`ActiveProjectCapability`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.activeprojectcapability)(\<expression>=[`ProjectCapability`](/dotnet/api/microsoft.visualstudio.extensibility.projectcapability)) | True whenever solution has a project with capabilities matching the provided subexpression. An expression can be something like `VB | CSharp`. For more about project capabilities, see [Project query API overview](../project/project.md). |
64
+
|[`ProjectAddedItem`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.projectaddeditem)(\<pattern>=\<regex>) | The term is true when a file matching the "pattern" is added to a project in the solution that is opened. |
65
+
|[`SolutionHasProjectCapability`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.solutionhasprojectcapability)(\<expression>=[`ProjectCapability`](/dotnet/api/microsoft.visualstudio.extensibility.projectcapability)) | True whenever solution has a project with capabilities matching the provided subexpression. An expression can be something like `VB | CSharp`. For more about project capabilities, see [Project query API overview](../project/project.md). |
66
+
|[`SolutionState`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.solutionstate)(\<state>=[`SolutionState`](/dotnet/api/microsoft.visualstudio.extensibility.solutionstate)) | True when solution state matches the provided value, see [solution states](#solution-states) for list of values. |
72
67
73
68
For compatibility reasons, the following legacy activation constraints are also supported:
74
69
75
70
| Term | Description |
76
71
| -- | -- |
72
+
|[`ActiveProjectBuildProperty`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.activeprojectbuildproperty)(\<property>=\<regex>) | The term is true when the selected project has the specified build property and the property value matches the regex pattern provided. |
73
+
|[`ActiveProjectFlavor`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.activeprojectflavor)(\<guid>) | True whenever the selected project has a flavor matching the given project type GUID. |
77
74
|[`SolutionHasProjectBuildProperty`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.solutionhasprojectbuildproperty)(\<property>=\<regex>) | The term is true when solution has a loaded project with the specified build property and property value matches to regex filter provided. |
78
75
|[`SolutionHasProjectFlavor`](/dotnet/api/microsoft.visualstudio.extensibility.activationconstraint.solutionhasprojectflavor)(\<guid>) | True whenever a solution has project that is flavored (aggregated) and has a flavor matching the given project type GUID. |
79
76
80
77
## Solution states
81
78
82
-
The solution state refers to the state of the solution and its projects, whether a solution is loaded, whether it has zero, one, or multiple projects, and whether it is building.
83
-
84
-
The following table shows the possible solution states:
85
-
86
-
| State | Description |
87
-
| -- | -- |
88
-
| NoSolution | No solution loaded. |
89
-
| Exists | A solution is opened but may be in loaded or loading state. |
90
-
| FullyLoaded | A solution is opened and fully loaded. |
91
-
| Empty | Solution contains no projects but may contain solution items. |
92
-
| SingleProject | Solution contains a single project. |
The [solution state](/dotnet/api/microsoft.visualstudio.extensibility.solutionstate) refers to the state of the solution and its projects, whether a solution is loaded, whether it has zero, one, or multiple projects, and whether it is building.
95
80
96
81
Activation constraints that correspond to solution states can be combined in the same way as any other activation constraints. For example, you can combine an activation constraint that specifies a `FullyLoaded` solution and a `SingleProject` solution to capture single-project solutions when they are fully loaded.
Currently, the client context is limited to a [small set of values](/dotnet/api/microsoft.visualstudio.extensibility.clientcontextkey.shell#properties) in IDE state.
@@ -130,7 +130,7 @@ There are just a few noteworthy things in this code:
130
130
131
131
1.`MyColor.Color` is a `string` but it's used as a `Brush` when data bound in XAML, this is a capability provided by WPF.
132
132
1. The `AddColorCommand` async callback contains a 2-second delay to simulate a long-running operation.
133
-
1. We use [ObservableCollection\<T\>](/dotnet/api/system.collections.objectmodel.observablecollection-1), which is supported by Remote UI, to dynamically update the list view.
133
+
1. We use [ObservableList\<T\>](microsoft.visualstudio.extensibility.ui.observablelist-1), which is an extended [ObservableCollection\<T\>](/dotnet/api/system.collections.objectmodel.observablecollection-1) provided by Remote UI to also support range operations, allowing better performance.
134
134
1.`MyToolWindowData` and `MyColor` don't implement [INotifyPropertyChanged](/dotnet/api/system.componentmodel.inotifypropertychanged) because, at the moment, all properties are readonly.
@@ -89,7 +88,7 @@ internal class SampleCommand : Command
89
88
90
89
*Compile-time constants* are subject to additional limitations compared to normal properties, for example they must be readonly and their initialization code can't include references to non-static members or multi-statement imperative code blocks. These restrictions are enforced by the VisualStudio.Extensibility build tools and results in error messages like the following:
91
90
92
-
> Property SampleCommand.CommandConfiguration is a compile-time constant. References to user-defined non-static members are not supported when evaluating compile-time constant values.
91
+
> An issue was encountered when evaluating the compile-time constant SampleCommand.CommandConfiguration. References to user-defined non-static members are not supported when evaluating compile-time constant values.
93
92
94
93
In general, the extension shouldn't reference *compile-time constant* configuration properties at run time.
95
94
@@ -108,9 +107,7 @@ public abstract class Command : ExecutableCommandHandler, IVisualStudioContribut
108
107
...
109
108
```
110
109
111
-
Onrareoccasions, configurationpropertiesareoptional. Forexample, the `Extension` classhasavirtual `ExtensionConfiguration` propertywhichincludessomelesscommonconfigurations.
112
-
113
-
Incertaincases, youmayneedtoimplementmultipleconfigurationpropertiesonthesameclass. Thisiscommon when extending `ExtensionPart` and implementing multiple interfaces, each one requiring its own configuration property.
110
+
Onrareoccasions, configurationpropertiesmaybeoptional. Incertaincases, youmayneedtoimplementmultipleconfigurationpropertiesonthesameclass. Thisiscommon when extending `ExtensionPart` and implementing multiple interfaces, each one requiring its own configuration property.
The [MarkdownLinter](https://github.com/Microsoft/VSExtensibility/tree/main/New_Extensibility_Model/Samples/MarkdownLinter/TextViewEventListener.cs) project shows a sample of a Visual Studio contribution property being referenced by another configuration property:
Copy file name to clipboardExpand all lines: docs/extensibility/visualstudio.extensibility/inside-the-sdk/extension-anatomy.md
+24-7Lines changed: 24 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -16,13 +16,30 @@ An extension utilizing VisualStudio.Extensibility typically has several componen
16
16
17
17
## Extension instance
18
18
19
-
The starting point for each extension is an instance of `Microsoft.VisualStudio.Extensibility.Extension`. This instance contains the necessary methods for Visual Studio to query services provided by the extension. It also provides virtual methods for the extension to provide localized resources and extension-owned local services to be shared between the components of the extension.
20
-
21
-
Extension projects have their own class that derives from `Microsoft.VisualStudio.Extensibility.Extension` to customize certain aspects of the extension.
22
-
23
-
Extensions must have a class that derives from `Microsoft.VisualStudio.Extensibility.Extension`. For an example implementation, see [MarkdownLinter](https://github.com/microsoft/VSExtensibility/tree/main/New_Extensibility_Model/Samples/MarkdownLinter).
24
-
25
-
For extension developers that are familiar with the existing VS SDK APIs, this class is similar to `AsyncPackage` class that is used in the VS SDK extensibility model.
19
+
Extensions must have a class that derives from [`Extension`](/dotnet/api/microsoft.visualstudio.extensibility.extension). For an example implementation, see [MarkdownLinter](https://github.com/microsoft/VSExtensibility/tree/main/New_Extensibility_Model/Samples/MarkdownLinter).
20
+
21
+
An instance of the `Extension` class is the starting point for the extension's execution. This instance contains the necessary methods for Visual Studio to query services provided by the extension. It also provides virtual methods for the extension to provide localized resources and extension-owned local services to be shared between the components of the extension.
22
+
23
+
The configuration for the `Extension` class also contains the [metadata](/dotnet/api/microsoft.visualstudio.extensibility.extensionconfiguration.metadata) for the extension which is shown in the Visual Studio [Manage Extensions window](/visualstudio/ide/finding-and-using-visual-studio-extensions?view=vs-2022#use-the-manage-extensions-dialog-box) and, for published extensions, on the [Visual Studio Marketplace](https://marketplace.visualstudio.com/).
For extension developers who are familiar with the existing VS SDKAPIs, the `Metadata` containedin `ExtensionConfiguration` isusedtogeneratethe [.vsixmanifest](/visualstudio/extensibility/anatomy-of-a-vsix-package#the-vsix-manifest) file. Also, the `Extension` classissimilartothe [`AsyncPackage`](/dotnet/api/microsoft.visualstudio.shell.asyncpackage) classthatisusedintheVSSDKextensibilitymodel.
0 commit comments