in-proc ProjectQueryableSpace
LeeMSilver opened this issue · comments
https://learn.microsoft.com/en-us/visualstudio/extensibility/visualstudio.extensibility/project/project?view=vs-2022
On the above page is sample code for setting up in-proc Project query workspace as follows:
IProjectSystemQueryService queryService = await package.GetServiceAsync<IProjectSystemQueryService, IProjectSystemQueryService>(); ProjectQueryableSpace workSpace = queryService.QueryableSpace;
What is package
?
I found the answer by ILSpy
ing ProjectQueryAPIBrowser.dll
.
Microsoft.VisualStudio.Shell.AsyncPackage package = (Microsoft.VisualStudio.Shell.AsyncPackage)(Object)this;
.
I think the above statement should be added as the first line to the sample code above so there are no questions about package
.
Hi @LeeMSilver
Thank you for bringing this to our attention, and we will update the documentation accordingly.
package
in this case is an AsyncPackage, which represents a package for Visual Studio extension development.
More information on building an 'in-proc' extension can be found here: https://learn.microsoft.com/en-us/visualstudio/extensibility/visualstudio.extensibility/get-started/in-proc-extensions?view=vs-2022
Please let us know if you have any more questions!
Closing this issue. An update has been made to the documentation explaining package.
The new documentation now reads
"In the following code excerpt, package represents an instance of AsyncPackage, a class utilized in the development of Visual Studio extensions."
The problem is that AsyncPackage
is abstract and an instance cannot be directly created. It is not documented how to create the class package
.
I'm thinking something like this needs to be added to the sample code (or as an additional sample):
class MyAsyncPackage<IProjectSystemQueryService> : AsyncPackage
{
}
and the sample code updated to add as the following as the first statement
MyAsyncPackage<IProjectSystemQueryService> package = new();
I need to mention that when I changed my code to look like the above
IProjectSystemQueryService queryService = await package.GetServiceAsync<IProjectSystemQueryService, IProjectSystemQueryService>();
throws a ServiceUnavailableException
. (See issue #358)