Consume .Net Core library from .Net standard project - wpf

I have a standard WPF application developed in .Net framework 4. Now, my client wants a website which I am planning to develop using .Net Core. In order to share the business logic, I need to move the database along business layer to a separate project and here I am planning to use .Net Core. So, all the layers i.e. Data/ Business/ API will be re-written using latest version of .Net Core.
Would I be able to reference business layer written in .Net Core from WPF (.Net Framework 4) project?
Any pointers will be highly appreciated.....

You should implement the common functionality in a .NET Standard library. You will then be able to reference this assembly from all apps that are compatible with the version of the .NET Standard that your common project targets.
The various .NET implementations target specific versions of .NET Standard and the following table on MSDN lists all versions of .NET Standard and the platforms supported: https://learn.microsoft.com/en-us/dotnet/standard/net-standard.
The latest version of .NET Core (currently 2.0 at the time of writing) implements .NET Standard 2.0. The oldest version of the .NET Framework that implements .NET Standard 2.0 is 4.6.1. This means that your WPF app should target 4.6.1 to be able to consume a .NET Standard 2.0 assembly.
.NET Core 1.0 and .NET Framework 4.5 support .NET Standard 1.0.
The .NET Framework 4.0 doesn't support any version of .NET Standard though so you should re-target your WPF app against (at least) .NET Framework 4.5.

Would I be able to reference business layer written in .Net Core from WPF (.Net Framework 4) project?
The answer is yes. You can try it: In Visual Studio create a WPF application project and a .NET Standard library project and then add a reference from the application project to the library project.
There will be NuGet packages that you cannot reference in your .NET Standard project because they only support full .NET Framework but most popular NuGet packages can be referenced from a .NET Standard project. Your question is also tagged [entity-framework-6]. If you want to use Entity Framework from a .NET Standard project you will have to use Entity Framework Core as Entity Framework 6 requires the full framework.
You should probably create a quick spike to determine if you can build your application how you intend to.

Related

Selecting correct .Net Framework for basic WPF - NUGET package can't install

I have created my first WPF project and it is written in .NET framework 4.7.2
I have NO idea about the importance and functionality of this however I want to be able to install it in a few businesses with as little chance of them needing to install a new framework. Perhaps that isn't important and I should just include it in the installer, but that is what I am not sure of.
I tried rolling back to 4.5 .NET however now one of my packages will not install on that framework.
Install-Package : Could not install package 'FluentEmail.Mailgun 2.8.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does
not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
If I do any framework lower than 4.7.2 I can't see to run this, however I can't find documentation referring to this needing a specific framework to run.
Any pointers in the right direction would be helpful,
eg. Is the framework important for a basic WPF app not using any crazy tech, just a few API's and mainly data storage?
Can I force this package to install on an earlier based framework or is that going to fail?
The FluentEmail.Mailgun package targets .NET Standard 2.0 which you can see by expanding the Dependencies section at NuGet.org.
.NET Standard 2.0 is implemented by .NET Framework 4.6.1 and later which you read from the compatibility matrix in the docs.
This basically means that you need to target at least 4.6.1 to be able to consume the package in your app.
There is a caveat though:
While NuGet considers .NET Framework 4.6.1 as supporting .NET Standard 1.5 through 2.0, there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher.
So if you are developing a new app, you are recommended to either target .NET Framework 4.7.2 or later or even better .NET Core 3.1 or .NET 5.
If you want the full story of which versions that are officially supported on which operating systems, you should refer to the lifecycle FAQ in the docs.
Targeting 4.5 doesn't make much sense since the support for it ended back in January 2016.

Can i use .dll library targeted .net framework v3.5 in application having targeted framework 4.0?

Hello currently I'm working on desktop application using WPF. I create application by targeting .net framework 4.0. but I have facing some problems related targeted frameworks.
First there is a library which i have to use in my application.A library supports targeted .net framework v3.5 but I also want to use the DataGrid control (only available above than v4.0 targeted .net framework) for table so now i'm confuse what i should do now? how can i achieve my goal? i want to use both library + Datagrid control in my application which is targeting .net framework v4.0.
Thanks in advance :)

What versions of .NET and WPF, does the ModernUI framework support?

I'm working with a WPF app that was written using the ModernUI framework. I'm wondering what versions of the .NET Framework does the ModernUI support?
The ModernUI assemblies target .NET Framework 4.5 which means that the library is compatible with any version equal to or larger than 4.5.
You can confirm this by looking at the <TargetFrameworkVersion> elements in the .csproj files on GitHub:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

Dependency Injection in WPF and Asp.Net Core

I am using Asp.Net Core to write API Layer for one of my legacy application developed using WPF (.Net Framework 4.5). I have used https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/ in Business layer which I want to access from WPF application. The version of this DI is not supported by .Net Framework 4.5 so I am unable to use it from WPF. Any suggestions how should I go with this ? The other approach is to use anyother DI container supported by .Net framework 4.5 and Asp.Net Core
I have upgraded my WPF project to .Net Framework 4.6 and rest of the layers are created using .Net Standard Library 2.0.

Recompile .NET 2.0 UserControl Library in 3.5?

A set of UserControls I've developed for in-house use were written in .NET 2.0 but my current development is in .NET 3.5. Assuming the following:
no need to update these controls in my 2.0 projects
there are no 3.5 features I need in my library
Is there any advantage at all (beyond satisfying a misplaced sense of tidyness) for me to update my control library to 3.5?
I believe even if a machine using my controls doesn't have the .NET 2.0 runtime installed, my library will run fine if it has the 3.5 runtime.
The only reason to bring them to 3.5 would be the tidiness concern. Otherwise they will work just fine with .NET 3.5 in every other aspect. Keep in mind that 3.0 and 3.5 were library extensions to 2.0. I.e. They run top of 2.0. (Things changed with 4.0 however.)

Resources