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 have looked through project dependencies and I can't find anything related to "Windows Desktop".
- I have tried stepping back to the previous revision/commit of the repo and re-implementing the changes
- and
Microsoft.WindowsDesktop.App
is not present the build output (also not present recent builds on build server, before the latest - where it is). - when adding the new
DataStuff.SqlData
class library back in again and consuming in the app, sure enough,Microsoft.WindowsDesktop.App
appears again. - just removing usage of the class library again, conveniently clears
Microsoft.WindowsDesktop.App
- and
- a fair bit of googling
- using some dependency/decompile tools to try find any clues
- The closest thing I can find relating to "desktop" are analyzers in the web-app project under
Dependencies
>Analyzers
:System.Windows.Forms.Analyzers
System.Windows.Forms.Analyzers.CSharp
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.
I encountered the extra
Microsoft.WindowsDesktop.App
requirement in myApp.runtimeconfig.json
today as well. It turns out that happened after I updatedMicrosoft.EntityFrameworkCore.SqlServer
to 7.0.16, which was released only a few days earlier. Going back a version to 7.0.15 made theMicrosoft.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: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 guessingMicrosoft.Identity.Client.NativeInterop
orMicrosoft.Web.WebView2
must be the NuGet that's adding theMicrosoft.WindowsDesktop.App
requirement, although I don't know how to confirm for sure.