Click here to Skip to main content
13,152,321 members (39,043 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 22 Oct 2007

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.


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.


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


About the Author

Shahar Gvirtz
Web Developer
Israel Israel
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionWhy is the PSVersion always shown as 1? Pin
Member 1326709619-Jun-17 1:09
memberMember 1326709619-Jun-17 1:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 22 Oct 2007
Article Copyright 2007 by Shahar Gvirtz
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid