Skip to content

Commit 237897d

Browse files
committed
Remove custom IProjectCapabilitiesProvider docs
It's too hard to do this correctly, and generally other approaches are better.
1 parent 8e063cb commit 237897d

2 files changed

Lines changed: 31 additions & 55 deletions

File tree

doc/overview/about_project_capabilities.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ file extension does not help if you want to check for WPF vs. WinForms
66
vs. Windows 8 XAML, for example. There are a great many different aspects
77
to a project that may be present regardless of language. Do you want code
88
that runs against any Windows 8 targeting project regardless of language?
9-
Do you want to target just Javascript Win8 projects but not LightSwitch
9+
Do you want to target just JavaScript Win8 projects but not LightSwitch
1010
JS projects? Project capability checks are the answer.
1111

12+
## Checking capabilities
13+
1214
The presence of some capability can be detected on a given project with
1315
code such as:
1416

@@ -26,17 +28,42 @@ method in order to test for combinations of capabilities (including
2628
AND, OR, NOT logic). Read more about [the supported syntax and
2729
operators](https://msdn.microsoft.com/library/microsoft.visualstudio.shell.interop.ivsbooleansymbolexpressionevaluator.evaluateexpression.aspx).
2830

29-
## How to declare project capabilities in your project
31+
## Filtering MEF parts via capabilities
32+
33+
Classes exported via MEF can declare the project capabilities under which they apply. See [MEF](mef.md) for more information.
34+
35+
## Defining capabilities via MSBuild
3036

3137
Project capabilities can be declared in several ways, the easiest of which
32-
being to add this MSBuild item to your .targets file:
38+
being to add this MSBuild item to your `.targets` file:
3339

3440
```xml
3541
<ItemGroup>
3642
<ProjectCapability Include="MyOwnCapability" />
3743
</ItemGroup>
3844
```
3945

46+
## Defining fixed capabilities for a project type
47+
48+
Some capabilities are static/fixed for a given project type. These capabilities should be defined directly on the project type registration.
49+
50+
For example:
51+
52+
```csharp
53+
[assembly: ProjectTypeRegistration(
54+
projectTypeGuid: MyProjectType.Guid,
55+
displayName: "#1",
56+
displayProjectFileExtensions: "#2",
57+
defaultProjectExtension: "myproj",
58+
language: "MyLang",
59+
resourcePackageGuid: MyPackage.PackageGuid,
60+
Capabilities = "MyProject; AnotherCapability")] // Define capabilities here
61+
```
62+
63+
Capabilities defined via the `ProjectTypeRegistrationAttribute.Capabilities` property are available on all projects loaded for that project type. Multiple values are separated by semicolon (`;`).
64+
65+
Sometimes you'll need capabilities to be defined very early in a project's lifecycle. These fixed capabilities are available from
66+
4067
## Viewing a project's capabilities
4168

4269
To see the capabilities a CPS project defines, add the `DiagnoseCapabilities` project capability to turn on a tree in the VS Solution Explorer that lists all capabilities of the project:
@@ -96,7 +123,7 @@ It's very important that project capabilities you define fit this criteria:
96123
- Bad: `CS`
97124
- May include a version number, when necessary, but is usually discouraged.
98125

99-
### Dynamic project capabilities
126+
## Dynamic project capabilities
100127

101128
Capablities of a project can be changed without reloading the project.
102129
Read more about [dynamic project capabilities](dynamicCapabilities.md).

doc/overview/dynamicCapabilities.md

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,57 +53,6 @@ public MyComponent(ConfiguredProject configuredProject)
5353
The `DeployProviders` collection will contain a set of `IDeployProvider` filtered by the current capabilities
5454
of the configuredProject. The content of the collection can change over the time.
5555

56-
## Defining fixed capabilities for a project type
57-
58-
Some capabilities are static/fixed for a given project type. These capabilities should be defined directly on the
59-
project type registration.
60-
61-
For example:
62-
63-
```c#
64-
[assembly: ProjectTypeRegistration(
65-
projectTypeGuid: MyProjectType.Guid,
66-
displayName: "#1",
67-
displayProjectFileExtensions: "#2",
68-
defaultProjectExtension: "myproj",
69-
language: "MyLang",
70-
resourcePackageGuid: MyPackage.PackageGuid,
71-
Capabilities = "MyProject")]
72-
```
73-
74-
Capabilities defined via the `ProjectTypeRegistrationAttribute.Capabilities` property are available on all projects loaded for that project type.
75-
76-
## Dynamically producing project capabilities
77-
78-
Capabilities can be added to a project at run-time via code. To do so, export an instance of
79-
`IProjectCapabilitiesProvider`. The easiest way to do this is to subclass `ProjectCapabilitiesProviderBase`
80-
and override the `GetCapabilitiesAsync` method.
81-
82-
For example, if your project should only have a certain capability on Tuesday, you could use:
83-
84-
```c#
85-
[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectCapabilitiesProvider))]
86-
[AppliesTo("MyProjectCapability")] // Replace with capabilities that define when your provider should be active
87-
internal class TuesdayProjectCapabilityProvider : ProjectCapabilitiesProviderBase
88-
{
89-
[ImportingConstructor]
90-
public TuesdayProjectCapabilityProvider(UnconfiguredProject project)
91-
: base(nameof(TuesdayProjectCapabilityProvider), project.Services.ThreadingPolicy.JoinableTaskContext, project.Services.DataSourceRegistry, configuredProjectLevel: false)
92-
{
93-
}
94-
95-
protected override Task<ImmutableHashSet<string>> GetCapabilitiesAsync(CancellationToken cancellationToken)
96-
{
97-
// Replace this with whatever logic you require.
98-
return DateTime.Now.DayOfWeek == DayOfWeek.Tuesday
99-
? Task.FromResult(Empty.CapabilitiesSet.Add("Tuesday"))
100-
: Task.FromResult(Empty.CapabilitiesSet);
101-
}
102-
}
103-
```
104-
105-
Note there can be a chicken/egg problem here, where one capability enables a provider (via `AppliesTo`) that then adds another capability, and so on.
106-
10756
## How to prevent seeing capability changes in the middle of an execution
10857

10958
When changes are made to the project, just like other dataflows inside CPS, capabilites are being recalculated

0 commit comments

Comments
 (0)