Click here to Skip to main content
Click here to Skip to main content
Go to top

Create a Setup Project to Install Your PowerShell SnapIn

, 22 Oct 2007
Rate this:
Please Sign up or sign in to vote.
In this article, you'll learn how to create a setup project to deploy your code with 0 lines of code.

Introduction

After you create a PowerShell snap-in, you probably want to create an installer. The "regular" way is to install from the command line using installutil.exe. But, it's not a good solution when you want to deploy your project.

In this article, you'll learn to create an MSI Setup Project (includes GUI) in Visual Studio and install your snap-in with 0 lines of code and without using installutil.exe at all.

The Solution

Your Visual Studio solution includes the project with the cmdlet classes and the snap-inT the output of this project is a DLL which is installed by installutil.exe.

Now, to create an installer, right-click in Solution Explorer on the solution name, and choose "Add New Project". Then, go to the Other Project Types category and choose Setup and Deployment -> Setup Project template.

The Install Project

The install project has a few parts. We will use only the File System part, the Custom Actions part, and the GUI. To switch between these views, right click on the project name in Solution Explorer (if you can't see it, go to the View menu and click on Solution Explorer), in the context menu, go to the View submenu, and click on the part you want to edit.

The first thing you have to do is go to File System (right-click on the project name in Solution Explorer and choose View->File System) and add the output of the main project.

In Application Folder, right-click and go to Add->Project Output.

Screenshot - 2.jpg

Choose the project which includes the cmdlets (providers etc.) and the snap-in, and choose the Primary Output (the DLL, actually).

If you have any additional files, like Type Configuration files or Format Configuration files, add them.

Then, go to the Custom Actions view (right-click -> View->Custom Actions on project name in Solution Explorer), and add to the Install node a new custom action, by right-clicking and Add.

You will see something like this:

Screenshot - 3.jpg

Choose your project output item from the application folder (you added it in the first step, in the File System view) and click OK.

Now, your Custom Actions view will look like this:

Screenshot - 4.jpg

Now, do the same (add custom action, same as the previous step) in the Uninstall node. The Custom Action will look like this:

Screenshot - 5.jpg

Right click on the project name in Solution Explorer and click Build. By default, the Installer doesn't build every time you build the solution. You can change it from the Configuration Manager in the Build menu.

After you build it, just right click and choose Install, or use the EXE and the MSI file which were created.

That's all!!!

This is a screenshot from the installer:

Screenshot - 6.jpg

Screenshot - 7.jpg

After the Installer runs, this is the output of get-pssnapin registered:

Screenshot - 8.jpg

The installer automatically registers it. Now, your customer just has to use add-pssnapin from their PowerShell console to add it, or add it to their profile file.

If you have another application which uses the snap-in with Runspace, you can add the Custom Action to install the snap-in to the setup project of the host application (the application which uses the snap-in with Runspaces).

You can, of course, change the GUI, add steps etc.

The attached code sample

The attached code sample includes two projects:

  1. A snap-in project with a very simple cmdlet "Get-Proc" (in my previous article, you can read about how to create cmdlets).
  2. A setup project which installs the output DLL from the first project.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shahar Gvirtz
Web Developer
Israel Israel
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 22 Oct 2007
Article Copyright 2007 by Shahar Gvirtz
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid