1

I would like to create an installer for my self-hosted service written in .NET Core 3.1. I'm using Visual Studio 2019 so I had to install VisualStudioClient.MicrosoftVisualStudio2017InstallerProjects and this allowed me to create Setup Project.

So, everything now works ok, except that I can't run any code during the installation! In standard .NET Framework there was Installer class that enabled me to inject some functions, like "register and start service". But .NET Core has nothing like that!

So how can I run extra C# code after the installation is finished?

1 Answer 1

4

It turns out that Installer class is not supported anymore and probably won't be in foreseeable future.

The workaround is to you the service exe itself as as a host for custom code, run be parameters.

Steps:

  1. In the Solution, where your .Net Core service lies add the "Setup Project" project. (it must be the same solution)
  2. Go to File System -> Application Folder and add PublishItemsOutputGroup
  3. Go to custom actions view and add a custom action PublishItemsOutputGroup to Install with your exe name selected. (e.g. it should say (name) PublishItemsOutputGroup from MyApiService (Active))
  4. Set arguments to /my_Install
  5. Go you form Main in the service and add something like:
if (args.Length == 1)
{
       File.AppendAllText("test_install_ca.txt", args[0]);
       return;
}
  1. Once you run it, you will find test_install_ca.txt in System32 dir with the content /my_Install
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.