Skip to content

Commit 2f74457

Browse files
Update AsyncPackageAndMEF sample to declare the brokered service in its pkgdef (#542)
1 parent a1e11fa commit 2f74457

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

New_Extensibility_Model/Samples/AsyncPackageAndMEF/AsyncPackageAndMEF.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.14.40254" PrivateAssets="all" />
15-
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.14.40254" PrivateAssets="all" />
14+
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.14.40608" PrivateAssets="all" />
15+
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.14.40608" PrivateAssets="all" />
1616
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.6.36389" ExcludeAssets="runtime" />
1717
</ItemGroup>
1818
</Project>

New_Extensibility_Model/Samples/AsyncPackageAndMEF/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ protected override void InitializeServices(IServiceCollection serviceCollection)
208208
}
209209
```
210210

211+
We also need to declare that `MyBrokeredService` is provided by this extension. This information is provided by a `BrokeredServices` entry in the pkgdef file. But we can
212+
have that automatically generated by adding the following attribute to the `AsyncPackage` class:
213+
214+
```cs
215+
[ProvideBrokeredServiceHubService(IMyBrokeredService.Configuration.ServiceName, Audience = ServiceAudience.Local | ServiceAudience.RemoteExclusiveClient)]
216+
public sealed class MyPackage : AsyncPackage
217+
{
218+
```
219+
220+
Note that the brokered service is provided by the VisualStudio.Extensibility part of the extension. We simply leverage the ability of attributes on the `AsyncPackge` to
221+
automatically generate the necessary pkgdef entries.
222+
211223
Now the `AsyncPackage` can retrieve a [proxy of the brokered service](https://microsoft.github.io/vs-streamjsonrpc/docs/proxies.html#proxy-traits) and interact with it:
212224
213225
```cs

New_Extensibility_Model/Samples/AsyncPackageAndMEF/VSSDK/MyPackage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace AsyncPackageAndMEF;
1313
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
1414
[Guid(MyPackage.PackageGuidString)]
1515
[ProvideService(typeof(MyService), IsAsyncQueryable = true)]
16+
[ProvideBrokeredServiceHubService(IMyBrokeredService.Configuration.ServiceName, Audience = ServiceAudience.Local | ServiceAudience.RemoteExclusiveClient)]
1617
public sealed class MyPackage : AsyncPackage
1718
{
1819
public const string PackageGuidString = "ac1de0e2-bc69-4a63-bb7e-15f3274448c7";

0 commit comments

Comments
 (0)