chrisdot
chrisdot

Reputation: 789

.Net core 3: manually adding framework dependencies

Since the release of version 3.0, it is now possible to write WPF applications in .net core, and this is really nice!

On the other hand, on .net core, the dependency system now relies on full framework and no more and multiple nuget dependencies. This is not a problem until you want to mix for instance WPF and ASP.net core in the same application (I have a case where I want a UI with a webserver handling websockets endpoints).

When I create an ASP.Net core project using VS2019, I get these frameworks dependencies (in solution explorer, on the assembly Dependencies/Frameworks node):

On the other side when I create a core 3 WPF project, I get the following framework dependencies:

What I would like to get as dependencies would be teh following:

How can I manually add the Microsoft.NETCore.App into the WPF application (or in the other way round)? There's nothing in the csproj about that...

In the csproj of the asp.net core I get that:

<PropertyGroup>
  <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

And in the WPF application, I get that:

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>netcoreapp3.0</TargetFramework>
  <UseWPF>true</UseWPF>
</PropertyGroup>

Is there any trick?

Upvotes: 11

Views: 11457

Answers (1)

chrisdot
chrisdot

Reputation: 789

OK, I found it out (thanks Andrew!):

Just add that section in the csproj:

<ItemGroup>
  <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

So in my example I just had to add that into my WPF project.

The trick was that the project was not of the same type. Fo the WPF one we had:

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

Whereas for the asp.net core one we had:

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

This later one automatically embedds the Microsoft.AspNetCore.App reference, and the WPF one does not.

Upvotes: 28

Related Questions