Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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):

  • Microsoft.AspNetCore.App
  • Microsoft.NETCore.App

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

  • Microsoft.NETCore.App
  • Microsoft.WindowsDesktop.App.Ref

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

  • Microsoft.AspNetCore.App
  • Microsoft.NETCore.App
  • Microsoft.WindowsDesktop.App.Ref

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?

like image 530
chrisdot Avatar asked Nov 28 '19 14:11

chrisdot


People also ask

How do I add a reference to .NET Core library?

Add Class Library Reference To use a class library in your application, you must add a reference to the library to access its functionality. Right click on the project name of your console app in Solution Explorer and select Add ->Reference option.

Where are the NuGet dependencies defined in .NET Core application?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder.

What is Metapackages in .NET Core?

Metapackages describe a set of packages that are used together. Metapackages are referenced just like any other NuGet package. By referencing a metapackage, you have, in effect, added a reference to each of its dependent packages.


Video Answer


1 Answers

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.

like image 181
chrisdot Avatar answered Sep 28 '22 11:09

chrisdot