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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With