Skip to content

Commit 69e10b2

Browse files
authored
Merge pull request #2478 from changeworld/patch-11
Delete unnecessary spaces
2 parents f1a308b + 43e643d commit 69e10b2

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

docs/extensibility/creating-an-extension-with-a-vspackage.md

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,65 @@ ms.assetid: c0cc5e08-4897-44f2-8309-e3478f1f999e
66
author: "gregvanl"
77
ms.author: "gregvanl"
88
manager: jillfra
9-
ms.workload:
9+
ms.workload:
1010
- "vssdk"
1111
---
1212
# Create an extension with a VSPackage
13-
This walkthrough shows you how to create a VSIX project and add a VSPackage project item. We will use the VSPackage to get the UI Shell service in order to show a message box.
14-
15-
## Prerequisites
16-
Starting in Visual Studio 2015, you do not install the Visual Studio SDK from the download center. It is included as an optional feature in Visual Studio setup. You can also install the VS SDK later on. For more information, see [Install the Visual Studio SDK](../extensibility/installing-the-visual-studio-sdk.md).
17-
18-
## Create a VSPackage
19-
20-
1. Create a VSIX project named **FirstPackage**. You can find the VSIX project template in the **New Project** dialog under **Visual C#** > **Extensibility**.
21-
22-
2. When the project opens, add a Visual Studio package item template named **FirstPackage**. In the **Solution Explorer**, right-click the project node and select **Add** > **New Item**. In the **Add New Item** dialog, go to **Visual C#** > **Extensibility** and select **Visual Studio Package**. In the **Name** field at the bottom of the window, change the command file name to *FirstPackage.cs*.
23-
24-
3. Build the project and start debugging.
25-
26-
The experimental instance of Visual Studio appears. For more information about the experimental instance, see [The experimental instance](../extensibility/the-experimental-instance.md).
27-
28-
4. In the experimental instance, open the **Tools** > **Extensions and Updates** window. You should see the **FirstPackage** extension here. (If you open **Extensions and Updates** in your working instance of Visual Studio, you won't see **FirstPackage**).
29-
30-
## Load the VSPackage
31-
At this point the extension does not load, because there is nothing that causes it to load. You can generally load an extension when you interact with its UI (clicking a menu command, opening a tool window), or by specifying that the VSPackage should load in a specific UI context. For more information about loading VSPackages and UI contexts, see [Loading VSPackages](../extensibility/loading-vspackages.md). For this procedure, we'll show you how to load a VSPackage when a solution is open.
32-
33-
1. Open the *FirstPackage.cs* file. Look for the declaration of the `FirstPackage` class. Replace the existing attributes with following:
34-
35-
```csharp
36-
[PackageRegistration(UseManagedResourcesOnly = true)]
37-
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
38-
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
39-
[Guid(FirstPackage.PackageGuidString)]
40-
public sealed class FirstPackage : Package
41-
```
42-
43-
2. Let's add a message that lets us know that the VSPackage has loaded. We use the VSPackage's `Initialize()` method to do this, because you can get Visual Studio services only after the VSPackage has been sited. (For more information about getting services, see [How to: Get a service](../extensibility/how-to-get-a-service.md).) Replace the `Initialize()` method of `FirstPackage` with code that gets the <xref:Microsoft.VisualStudio.Shell.Interop.SVsUIShell> service, gets the <xref:Microsoft.VisualStudio.Shell.Interop.IVsUIShell> interface, and calls its <xref:Microsoft.VisualStudio.Shell.Interop.IVsUIShell.ShowMessageBox%2A> method.
44-
45-
```csharp
46-
protected override void Initialize()
47-
{
48-
base.Initialize();
49-
50-
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
51-
Guid clsid = Guid.Empty;
52-
int result;
53-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
54-
0,
55-
ref clsid,
56-
"FirstPackage",
57-
string.Format(CultureInfo.CurrentCulture, "Inside {0}.Initialize()", this.GetType().FullName),
58-
string.Empty,
59-
0,
60-
OLEMSGBUTTON.OLEMSGBUTTON_OK,
61-
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
62-
OLEMSGICON.OLEMSGICON_INFO,
63-
0,
64-
out result));
65-
}
66-
```
67-
68-
3. Build the project and start debugging. The experimental instance appears.
69-
70-
4. Open a solution in the experimental instance. You should see a message box that says **First Package Inside Initialize()**.
13+
This walkthrough shows you how to create a VSIX project and add a VSPackage project item. We will use the VSPackage to get the UI Shell service in order to show a message box.
14+
15+
## Prerequisites
16+
Starting in Visual Studio 2015, you do not install the Visual Studio SDK from the download center. It is included as an optional feature in Visual Studio setup. You can also install the VS SDK later on. For more information, see [Install the Visual Studio SDK](../extensibility/installing-the-visual-studio-sdk.md).
17+
18+
## Create a VSPackage
19+
20+
1. Create a VSIX project named **FirstPackage**. You can find the VSIX project template in the **New Project** dialog under **Visual C#** > **Extensibility**.
21+
22+
2. When the project opens, add a Visual Studio package item template named **FirstPackage**. In the **Solution Explorer**, right-click the project node and select **Add** > **New Item**. In the **Add New Item** dialog, go to **Visual C#** > **Extensibility** and select **Visual Studio Package**. In the **Name** field at the bottom of the window, change the command file name to *FirstPackage.cs*.
23+
24+
3. Build the project and start debugging.
25+
26+
The experimental instance of Visual Studio appears. For more information about the experimental instance, see [The experimental instance](../extensibility/the-experimental-instance.md).
27+
28+
4. In the experimental instance, open the **Tools** > **Extensions and Updates** window. You should see the **FirstPackage** extension here. (If you open **Extensions and Updates** in your working instance of Visual Studio, you won't see **FirstPackage**).
29+
30+
## Load the VSPackage
31+
At this point the extension does not load, because there is nothing that causes it to load. You can generally load an extension when you interact with its UI (clicking a menu command, opening a tool window), or by specifying that the VSPackage should load in a specific UI context. For more information about loading VSPackages and UI contexts, see [Loading VSPackages](../extensibility/loading-vspackages.md). For this procedure, we'll show you how to load a VSPackage when a solution is open.
32+
33+
1. Open the *FirstPackage.cs* file. Look for the declaration of the `FirstPackage` class. Replace the existing attributes with following:
34+
35+
```csharp
36+
[PackageRegistration(UseManagedResourcesOnly = true)]
37+
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
38+
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
39+
[Guid(FirstPackage.PackageGuidString)]
40+
public sealed class FirstPackage : Package
41+
```
42+
43+
2. Let's add a message that lets us know that the VSPackage has loaded. We use the VSPackage's `Initialize()` method to do this, because you can get Visual Studio services only after the VSPackage has been sited. (For more information about getting services, see [How to: Get a service](../extensibility/how-to-get-a-service.md).) Replace the `Initialize()` method of `FirstPackage` with code that gets the <xref:Microsoft.VisualStudio.Shell.Interop.SVsUIShell> service, gets the <xref:Microsoft.VisualStudio.Shell.Interop.IVsUIShell> interface, and calls its <xref:Microsoft.VisualStudio.Shell.Interop.IVsUIShell.ShowMessageBox%2A> method.
44+
45+
```csharp
46+
protected override void Initialize()
47+
{
48+
base.Initialize();
49+
50+
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
51+
Guid clsid = Guid.Empty;
52+
int result;
53+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
54+
0,
55+
ref clsid,
56+
"FirstPackage",
57+
string.Format(CultureInfo.CurrentCulture, "Inside {0}.Initialize()", this.GetType().FullName),
58+
string.Empty,
59+
0,
60+
OLEMSGBUTTON.OLEMSGBUTTON_OK,
61+
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
62+
OLEMSGICON.OLEMSGICON_INFO,
63+
0,
64+
out result));
65+
}
66+
```
67+
68+
3. Build the project and start debugging. The experimental instance appears.
69+
70+
4. Open a solution in the experimental instance. You should see a message box that says **First Package Inside Initialize()**.

0 commit comments

Comments
 (0)