.net-6.0asp.net-core-6.0runtime-configuration

Unexpected requirement of "Microsoft.WindowsDesktop.App" in ASP.NET Core app


Recent changes in my Visual Studio solution for an ASP.NET Core (.NET 6.0) API application have resulted in a requirement for "Microsoft.WindowsDesktop.App", with the framework entry being added to the .runtimeconfig.json file and I cannot see why. This is an issue for server deployment.

The significant part of the changes was adding a new class library, referenced and consumed in the main web-app project.

The new .runtimeconfig.json:

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.0"
      }
    ],
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.NullabilityInfoContext.IsSupported": true,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

The web-app .csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0-windows</TargetFramework>
    ...
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="*" Version="*" />
    ...
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\DataStuff.SqlData\DataStuff.SqlData.csproj" />
    ...
  </ItemGroup>

</Project>

The new class library DataStuff.SqlData.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    ...
  </PropertyGroup>

  <ItemGroup>
    <None Remove="Scripts\*.sql" />
    ...
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="Scripts\*.sql" />
    ...
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.5" />
  </ItemGroup>

</Project>

The new class:

using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace DataStuff.SqlData
{
    public class SqlSetup
    {
        public SqlSetup(string stringVal)
        {   //...
        }

        public async Task RunSetup()
        {   //...
        }
    }
}

SqlSetup is registered in the web-app services collection and called as a "start-up task" in a IHostedService

    public async Task StartAsync(CancellationToken cancellationToken)
    {   // ...
        await sqlSetup.RunSetup();
    }

As well as SqlSetup.cs, the DataStuff.SqlData project contains some embedded text files with SQL scripts. SqlSetup.RunSetup uses SqlCommand to run these scripts.


Investigation:

I am not sure that the analyzers affect the build ouput directly. There doesn't seem to be a way to remove them - easily in VS at least. I was suspecting that they were there as they potentially could be of use due to the windows part of the project TFM, though the target has always been net6.0-windows - as this is the supported target for one important package - and this has never resulted in a Microsoft.WindowsDesktop.App requirement in the past.


Any help in solving this will be appreciated. This could just be guidance on clearly tracking required runtimes from targets and dependencies.

Thanks.


Solution

  • I encountered the extra Microsoft.WindowsDesktop.App requirement in my App.runtimeconfig.json today as well. It turns out that happened after I updated Microsoft.EntityFrameworkCore.SqlServer to 7.0.16, which was released only a few days earlier. Going back a version to 7.0.15 made the Microsoft.WindowsDesktop.App requirement disappear.

    It looks like Microsoft.EntityFrameworkCore.SqlServer 7.0.16 brings in a few new packages that 7.0.15 does not. The dependencies are:

    Microsoft.EntityFrameworkCore.SqlServer 7.0.16
    > Microsoft.Data.SqlClient 5.1.4
    >> Microsoft.Identity.Client 4.56.0
    >>> Microsoft.Identity.Client.NativeInterop 0.13.8 [new]
    >>> Microsoft.Web.WebView2 1.0.864.35 [new]
    > Azure.Identity 1.10.3
    >> Microsoft.Identity.Client.Extensions.Msal 4.56.0
    >>> System.IO.FIleSystem.AccessControl 5.0.0 [new]
    

    In particular, it is interesting that the dependencies for Microsoft.Identity.Client 4.56.0 are:

    It so happens that I'm using net6.0-windows as the target framework too. So I'm guessing Microsoft.Identity.Client.NativeInterop or Microsoft.Web.WebView2 must be the NuGet that's adding the Microsoft.WindowsDesktop.App requirement, although I don't know how to confirm for sure.