Build service error using PowerShell 7.0.3 and netcoreapp31

Tool: Visual Studio 2017, Visual Studio Code
Version: 5.7.20

Trying to build a service exe in Visual Studio 2017 results in the following error:

    ------ Build started: Project: PowerShellProject2, Configuration: Debug Any CPU ------
    		Checking license
    		OutputPath is C:\Users\???\PowerShellProject1\PowerShellProject2\bin\Debug\
    		Packaging PowerShellProject2.ps1
    		Checking dotnet version.
    		3.1.405

    		3.1.405

    		Creating package project.
    		Using .NET Framework version: netcoreapp31
    		  Determining projects to restore...
      Restored C:\Users\???\AppData\Local\Temp\3\7c9583ef622540f1b083065ffa180b07\PowerShellProject2.csproj (in 1.58 sec).

    		  Determining projects to restore...
      Restored C:\Users\???\AppData\Local\Temp\3\7c9583ef622540f1b083065ffa180b07\PowerShellProject2.csproj (in 1.58 sec).

    		Packaging PowerShellProject2.ps1 -> C:\Users\???\PowerShellProject1\PowerShellProject2\bin\Debug\\PowerShellProject2.exe
    		Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
    Copyright (C) Microsoft Corporation. All rights reserved.

      Determining projects to restore...
      Restored C:\Users\???\AppData\Local\Temp\3\7c9583ef622540f1b083065ffa180b07\PowerShellProject2.csproj (in 1.98 sec).
    C:\Program Files\dotnet\sdk\3.1.405\Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Configuration.Install". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\???\AppData\Local\Temp\3\7c9583ef622540f1b083065ffa180b07\PowerShellProject2.csproj]
    ConsolePowerShellHost.cs(15,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\???\AppData\Local\Temp\3\7c9583ef622540f1b083065ffa180b07\PowerShellProject2.csproj]
    ConsolePowerShellHost.cs(314,46): error CS0246: The type or namespace name 'Installer' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\???\AppData\Local\Temp\3\7c9583ef622540f1b083065ffa180b07\PowerShellProject2.csproj]

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\PowerShell Tools for Visual Studio\PowerShellProTools.targets(5,5): error : Failed to build.
    Done building project "PowerShellProject2.pssproj" -- FAILED.

    Build FAILED.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

It does not matter what is the content of the .ps1. It can be even an empty file with just OnStart() and OnStop() functions. If selecting “Console” instead of “Service” the exe builds just fine.
Any idea?