I'm using the Visual Studio Installer Projects Extension to create a .msi for my project.
The installer seems to work ok for the most part, but it won't kick off my service after install and I have to run MyService.exe manually.
Is there a way to do this? Or could I inject some custom installer code somewhere?
Viusal Studio Installer projects don't expose Windows Installer's underlying ServiceInstall / ServiceControl tables. This forces developers to reinvent the wheel using custom actions resulting in fragile installers.
Windows Installer XML can author merge modules that properly implement ServiceInstall / Service Control. You can then reference that merge module into your Visual Studio Installer to accomplish the task with breaking best practices. A discussion of this can be found here:
Augmenting InstallShield using Windows Installer XML - Windows Services
Redemption of Visual Studio Deployment Projects
IsWiX Tutorials - How to author a Windows Service using WiX / IsWiX
Microsoft has described the process of creating a service installer in this MSDN article: How to: Add Installers to Your Service Application
See if this helps:
http://www.installsite.org/pages/en/msi/tips.htm
Scroll down to Installing Services with Visual Studio.
It's a tool for adding the ServiceInstall/ServiceControl features to a VS setup. I haven't updated it for a while but all the source is there.
Related
I have an application C#. This application use a Project "Visual Studio Installer/Setup Project" for the setup. I have to change it for a "Windows Installer XML/Setup Project".
The VS Installer use
a Custom Action
a class public partial class InstallerDB : System.Configuration.Install.Installer. Used to install the database
Maybe something else (I don't really understand how this installer Works"
I created a WiX project. In the product.wxs I added a call to the custom action. But how can I call the project with the class InstallerDB ?
And how can I be sure to do exactly the same setup ?
WiX doesn't support installer class custom actions for many reasons, primarily because the Windows Installer team didn't support them and they arrived only in Visual Studio setup projects that Microsoft attempted to get rid of.
WiX has its own support for managed code custom actions derived from the DTF effort to make them more acceptable for Windows Installer, so convert your custom action to this format. Examples are:
https://blogs.msdn.microsoft.com/jschaffe/2012/10/23/creating-wix-custom-actions-in-c-and-passing-parameters/
http://www.codeproject.com/Articles/132918/Creating-Custom-Action-for-WIX-Written-in-Managed
If you install services with custom action installer classes then don't bother - WiX supports the built-in Windows Installer features to do this (which Visual Studio setups never did). See the WiX ServiceInstall element, and ServiceControl for stopping and starting. The fact that Visual Studio setups use installer classes can give people the impression that they are required for installation of .NET services, but that's not the case.
I have written a Windows Service.
I now want to package it up in an installer.
I have used the VS2013 x86 Native Tools Command Prompt and then used the commands:
To install it:
installutil httpapiservice.exe
To uninstall it:
installutil httpapiservice.exe /u
This works perfectly. I can see the new service in "Services" and stop and start it no problem.
I then proceeded to right click on the project and select "Publish" and it produced a setup.exe
But, when I run the setup.exe I can see it "downloading and extracting" the files. It looks like it's installing but nothing appears in "Services"
Can anyone tell me if I am doing it correctly please?
Thanks
You need to add a setup project to your solution to build an installer executable.
Unfortunately Microsoft removed their setup project template from Visual Studio 2012 onwards, which would have done the job.
This means you are stuck with one of the alternatives, which are either less functional, harder to set up, or expensive.
NOTE - scroll down to EDIT 3 for my recommended solution. The rest of this post is just to highlight alternatives.
If you fancy the free route you can add on InstallShield Limited Edition to Visual studio, and use it to create a setup project for your solution. It will work for windows service setup projects in the latest version, but is generally considered pretty rubbish and limited. Here's the instructions for this: link
WiX is a free open source alternative, which is far more functional, but tricky to set up.
EDIT -
Here's an article describing how to use WiX to create a setup project: http://www.schiffhauer.com/wix-template-for-installing-a-windows-service/
EDIT 2 -
As of today (22/04/2014) Microsoft have reinstated the setup project in Visual Studio 2013 as an Visual studio extension - see this post
I've not tried it myself, but it's presumably the same as the VS2010 setup project, which wasn't too hard to learn (and there's plenty of help available on the internet) I'd definately recommend you try this for creating your setup program!
EDIT 3 (Apr 2016) -
I'd highly recommend you use the Visual Studio Installer Projects Extension (as mentioned in the above edit) for creating simple installers for your windows services (and other programs too). The installers it creates are simple, but professional looking enough for simple or small projects.
The extension for Visual Studio 2013 is here
The extension for Visual Studio 2015 is here
The extension for Visual Studio 2017 is here
An article describing how to create a setup project for a windows service using the old VS2010 Setup project is here. Although this is an old article it can be applied directly to the new Installer Project extensions linked above. (Thanks EbbnFlow for the link)
I ended up zipping up the software and including installutil.exe and simply gave the customer instructions have to install and uninstall.
Seems to have worked perfectly.
HTH
It seems you want to use ClickOnce (publish) to install a service. This isn't possible without a hassle but you can try to do it as described in this answer.
These official Microsoft extensions provide support for Visual Studio Installer Projects in Visual Studio 2013 https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d
and Visual Studio 2015 https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9
With these extension and the video in the previous post I was able to make a setup project for a windows service in Visual Studio Community 2015.
Don't forget to add the custom actions for install and uninstall (as described in the video) and also don't forget to add the installer class to your service project to get your service correctly installed under system --> services.
I've added the serviceProcessInstaller and the serviceInstaller-component by code and configured it like this:
public XxxServiceInstaller()
{
InitializeComponent();
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
// Service Account Information
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;
// Service Information
serviceInstaller.ServiceName = "your service name";
serviceInstaller.DisplayName = "your service display name";
serviceInstaller.StartType = ServiceStartMode.Manual; // or automatic
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
this.AfterInstall += new InstallEventHandler(ProdSSSyncServiceInstaller_AfterInstall);
}
void XxxServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
ServiceController sc = new ServiceController("your service name");
// start immediately
sc.Start();
}
I've finished my C# application, but I have a little problem:
When I try to run my application in another PC, I need always to Install .NET Framework 4.0.
Is there something to do to make it work without installing the framework from internet?
I tried before InnoSetup for a VB6 application, but I'm not sure if it's going to work for .NET 4.0!
Any ideas?
Use Visual Studio Setup project. Setup project can automatically include .NET framework setup in your installation package:
Here is my step-by-step for windows forms application:
Create setup project. You can use Setup Wizard.
Select project type.
Select output.
Hit Finish.
Open setup project properties.
Chose to include .NET framework.
Build setup project
Check output
Note: The Visual Studio Installer projects are no longer pre-packed with Visual Studio. However, in Visual Studio 2013 you can download them by using:
Tools > Extensions and Updates > Online (search) > Visual Studio Installer Projects
You need to create installer, which will check if user has required .NET Framework 4.0. You can use WiX to create installer. It's very powerfull and customizable. Also you can use ClickOnce to create installer - it's very simple to use. It will allow you with one click add requirement to install .NET Framework 4.0.
WiX is the way to go for new installers. If WiX alone is too complicated or not flexible enough on the GUI side consider using SharpSetup - it allows you to create installer GUI in WinForms of WPF and has other nice features like translations, autoupdater, built-in prerequisites, improved autocompletion in VS and more.
(Disclaimer: I am the author of SharpSetup.)
Include an Setup Project (New Project > Other Project Types > Setup and Deployment > Visual Studio Installer) in your solution. It has options to include the framework installer. Check out this Deployment Guide MSDN post.
I have a windows service to detect desktop lock and unlock. I tried to create an EXE setup file (myapp.exe) for my windows service. the service detects lock/unlock event and writes it in a text file.
I was able to do this in visual studio 2010, but i don't find any documents as how to create this exe setup file using visual studio 2012. I found some videos in youtube which shows creating exe setup file but when i tried i don't find my service installed as a windows service. It is installing like normal application.
Good article explaining how to create a windows service installer with Visual Studio and WiX is available here.
With Visual Studio 2012 you will need a third party tool to create setups. I would suggest WiX. There is good information on installing and starting Windows Services using WiX here although you will probably need to read some beginners tutorials first.
The alternative is to load your project in VS2010 and add a setup project there. You will need to perform the build in VS2010. VS2012 will still load your solution, but it will ignore (unload) your setup project. The same .sln will open up fine in VS2010 and VS2012.
i want to know how to create a installer similar to visual studio 2010 setup file.
thanks in advance.
There is an open source script driven project called Wix which you could use here: http://wix.sourceforge.net/
There are some additional MSI installation file utilities.
Hopefully this helps.
WiX toolset is used to create Windows Installer based installers, MSI files. Visual Studio setup uses MSI to make changes to the system. Although MSI is very powerful, it provides limited UI experience, which, however, is quite enough for most setups.
Visual Studio setup uses a regular application that collects information from the user. Then it uses External UI (see MsiSetExternalUI function) to monitor and display progress of the installation.
Look at Setup guidelines and make your setup experience as simple as possible, but not simpler.