IVsPackage.SetSite Method
Initializes a VSPackage with a back pointer to the environment.
Namespace: Microsoft.VisualStudio.Shell.Interop
Assembly: Microsoft.VisualStudio.Shell.Interop (in Microsoft.VisualStudio.Shell.Interop.dll)
Syntax
'宣言
Function SetSite ( _
psp As IServiceProvider _
) As Integer
'使用
Dim instance As IVsPackage
Dim psp As IServiceProvider
Dim returnValue As Integer
returnValue = instance.SetSite(psp)
int SetSite(
IServiceProvider psp
)
int SetSite(
[InAttribute] IServiceProvider^ psp
)
function SetSite(
psp : IServiceProvider
) : int
Parameters
psp
Type: Microsoft.VisualStudio.OLE.Interop.IServiceProvider[in] Pointer to the IServiceProvider Interface through which the VSPackage can query for services.
Return Value
Type: System.Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.
Remarks
COM Signature
From vsshell.idl:
HRESULT IVsPackage::SetSite(
[in] IServiceProvider *pSP
);
This is the most important method in the IVsPackage Interface.
In your implementation of this method, you can:
Store psp.
Load persistent data using the interfaces IVsPersistSolutionOpts Interface and IVsPersistSolutionProps Interfaces.
Proffer services, if any.
Register available document factory editors, if any.
Register available project type factories, if any.
Request services that are implemented by other VSPackages
You must have proffered your services by the time these steps are complete. Otherwise, your request for a service may load a VSPackage that requests a service you provide. However, because you have not proffered it yet, the load of the other VSPackage fails, and you cannot gain access to the requested service, possibly causing load failure.
Returning an error result code results in the environment closing the VSPackage and releasing its resources.
In your implementation of this method you should not assume that UI would be available. Do not try to add a pane to Output Window or use any other service that relies on UI to be available. For example, when devenv is invoked with /setup SetSite gets called and the UI is not available.
Permissions
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.