5

I am developing a .NET Core application using Visual Studio Code and the dotnet sdk on C#. I have two targets frameworks in the csproj:

<TargetFrameworks>netcoreapp2.0;net471</TargetFrameworks>

and I want to compile a console application when the target is netcoreapp2.0 and a Windows Service when the target is net471. To achieve that I added the preprocessor symbol NET471 in the code associated with the service.

I found that to make a Windows service and be able to use the InstallUtil.exe, it is necessary to make a class that inherit from ServiceBase, and other that inherit from Installer. This Installer class is in the System.Configuration.Install namespace.

The problem is that when I want to build for net471 like this:

dotnet build -f net471

it failed with this error:

MyServiceInstaller.cs(4,28): error CS0234: The type or namespace name 'Install' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?) [C:\Users\jjamardo\service-test\service-test.csproj] MyServiceInstaller.cs(9,39): error CS0246: The type or namespace name 'Installer' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\jjamardo\service-test\service-test.csproj] 0 Warning(s) 2 Error(s)

I google it a lot, but I couldn't find anything helpful.

Trying a lot of things I managed to compile it BUT using net461 as the target framework.

dotnet build -f net461

This might work, but I don't want to downgrade to 4.6.1. I tried to make a .NET Framework 4.7.1 in Visual Studio 2017 and the application works fine, so I assume that the namespace is still existing. I do not understand why using dotnet compiles with the target 4.6.1 but fails with 4.7.1.

So, the question is: how can I make a Windows service using dotnet, with net471 as the target framework. Is there any other way to make a Windows service without inherit from ServiceBase and Installer?

Thanks!

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
jjamardo
  • 267
  • 3
  • 9

3 Answers3

5

There's NuGet package that implements the System.Configuration.Install API 1:1: Link to the package

KennyPowers
  • 4,925
  • 8
  • 36
  • 51
1

While not a good answer, the System.Configuration.Install namespace is not supported on .NET Core.

Alex Ghiondea - MSFT
  • 3,182
  • 1
  • 8
  • 11
0

For net471 did you add to your project?

<ItemGroup>
    <Reference Include="System.Configuration.Install" />
</ItemGroup>
Gregory A. Owen
  • 188
  • 1
  • 8