I have started to learn Xamarin. From what I read, .Net Standard allows a developer to use code from another .Net platform into Xamarin.
The examples that I read only talk about MVC or .Net Core. The documentation says that the developer can use .Net Standard with .Net Framework 4.6.1. Visual Studio 2019 has the option to include an Asp.Net Core Web API Project as part of a mobile backend.
Is there there a .Net Framework option available?
I have a lot of .Net Framework Pages that I would like to include into Xamarin.
Do I need to rewrite all the code or is there a conversion process I need to do?
.NET Standard defines the common subset of libraries and features that are shared by both .NET Core and .NET Framework. If your existing code is using .NET Framework, it's possible that most or all of the framework features that the code relies on are supported by .NET Standard. If so, it will be easy to port the code to a .NET Standard assembly, which can be used by Xamarin. The difficulty of the port will depend on how many .NET Framework-specific features you're using.
Microsoft provides a tool to analyze how compatible your code is, you can find details here
Related
Is there a way to use a C# library written in the UWP framework in a .NET Framework (or .NET Standard) application?
I try to get a Bluetooth (BLE) module working for a .NET Framework application in Windows 11. As far as I know, the native Bluetooth support is only possible using UWP, so I can't switch here. The .NET Framework application is also fixed, it contains external libraries from suppliers that can't be updated to .NET Standard or .NET 6. However, I can write an adapter class that uses .NET Standard 2.0, so I can work with it if a solution for .NET Standard exists.
When I try to reference a UWP class from .NET Framework or .NET Standard, I always get an error like this:
"Project BLE_Module is not compatible with netstandard2.0(.NETStandard,Version=v2.0). Project BLE_Module supports: uap.10.0.17763(UAP,Version=v10.0.17763)"
I know I can reference .NET Standard classes from UWP, but that does not help me, as the UWP module is just an execution module for Bluetooth requests and does not include any business logic.
What can I do to resolve the problem? I could write the BLE_Module as a stand-alone service and interact with the service from the main program during runtime, but before I embark on this journey, I would like to know if there are any possibilities to make it work without such a specific solution (that also reduces testability and increases bug chances).
Is there a way to use a C# library written in the UWP framework in a .NET Framework (or .NET Standard) application?
Short answer: No.
That's why .NET Standard was introduced in the first place, i.e. to be able to share common code between different .NET implementations.
A class library that targets a specific platform, such as UWP, cannot be consumed from an app that targets another platform, such as for example the .NET Framework.
Native Bluetooth support does not require UWP. The Bluetooth libraries are written for the WinRT API, so you can use them from C++ or .NET Framework desktop applications.
See https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance for more info.
If you however have an additional layer written in UWP on top of the native Bluetooth libraries, then I'm not sure if that can be consumed in a normal .NET Framework application.
I've been trying to determine if I can call a .Net5 library/DLL from .Net Framework4.x code. There seems to be a number of articles about using .Net Standard but now that things are suppose to be consolidated into .Net 5 I'm not sure if/how things have changed. Any good references or articles out there? Can I even access a .Net5 Library from a framework app?
Check the official documentation
You mentioned:
now that things are suppose to be consolidated into .Net 5
Not really true, as you can see in the documentation:
.NET 5.0 is the next major release of .NET Core following 3.1. We named this new release .NET 5.0 instead of .NET Core 4.0 for two reasons:
We skipped version numbers 4.x to avoid confusion with .NET Framework 4.x.
We dropped "Core" from the name to emphasize that this is the main implementation of .NET going forward. .NET 5.0 supports more types of apps and more platforms than .NET Core or .NET Framework.
So it's still net core in all but name. You still need to use .net standard to support both platforms. Check te comments for compatibility.
This might also be interesting to you: choosing-core-framework-server
I'm still getting to grips with .Net Standard vs .Net Core after many years of development ASP.NET Framework. I have set up a new Web Api "app" which targets netcoreapp3.1 framework along with a middle-tier/Business Logic ClassLib and Data Access ClassLib, both of which target .Net Standard for maximum future compatibility. However, I can't seem to use ISystemClock from the Microsoft.AspNetCore.Authentication namespace in the .Net Standard classlibs!
From reading this SO question, I believe this might be because netstandard2.0 might not implement Microsoft.AspNetCore.App framework. Is this correct?
If it doesn't, should I:
Provide my own IMySystemClock interface in my class libraries which
the "app" itself can implement a trivial concrete class for?; or
Change my class middle and data access tiers to netcoreapp3.1
framework (seems over kill and restrictive to do this)?
Something else? Maybe I am missing the point of .Net Standard`?
A service (like ISystemClock) to provide the current (real or mock) time seems quite a fundamental service so I'm unsure why it's not appearing in .net standard framework?
Thanks
BloodBaz
If you want to access that functionality from a library, change the target framework of your library to .NET Core 3.1. Libraries can be built in .NET Standard or .NET Core. You can't use .NET Core functionality within a .NET Standard library, but you can do the reverse. Use .NET Standard functionality within a .NET Core library.
Also as a side note, unless it's required for compatibility reasons, I recommend you switch to .NET Standard 2.1. Visual Studio defaults new projects to .NET Standard 2.0, but a ton of new functionality was added in .NET Standard 2.1.
I spent years in the .NET Framework, so I feel the confusion. It took me a while to get used to it. I have a huge project I recently migrated over from .NET Framework to .NET Standard / .NET Core. What I ended up doing was dividing my code up into three sections. A .NET Standard 2.1 library with all the non .NET Core specific common code, a .NET Core 3.1 library with all my .NET Core specific common code (which referenced my .NET Standard library), and my applications as .NET Core 3.1 projects (which referenced my .NET Core 3.1 library).
Make sure you take a read at the answer in this question as well: What is the difference between .NET Core and .NET Standard Class Library project types?
When I create new UWP project it automatically references .NET Core. Is it possible to run it on .NET? Why it needs .NET Core? I can't find any valuable information about this...
It needs .NET Core because it is built on .NET Core, much like WPF is built on the .NET framework.
So no, you cannot change it to run on the standard .NET framework any more than you can make WPF run on .NET Core.
The .NET Core Framework is a new version of .NET for modern device and cloud workloads. It’s a general-purpose and modular implementation of the Microsoft .NET Framework that can be ported and used in many different environments for a variety of workloads.
and No, you cannot run UWP project on .Net
althousg if you install previous version of VS then you can run it on .NET
I just can't understand why I can't use an old library in a .net Core app targeting Windows and the full .net framework (I don't care about multi-platform).
Just trying to understand the limits here. I don't want to hit a wall after investing too much into it.
Steps followed:
Create a new .Net core web Application
Added PetaPoco from NuGet (just an example)
Can't use the library
From a comment from you on a deleted answer to this question
It's not about this particular reference. I just want to understand why I can't use an arbitrary Windows DLL. (I don't care about multi-platform) – Eduardo Molteni
It appears you are not too concerned why this specific project is not working (the deleted answer you commented on covered that quite well and if it was not deleted I would have up-voted it) but why in general you can't use a .NET Framework DLL in a .NET Core project.
Here is a diagram showing the layout of the ".NET ecosystem"
Things built for .NET Framework can't use DLLs built specifically for .NET Core, and things built for .NET Core can't use DLLs built specifically for .NET Framework because they are two "siblings" in the hierarchy.
Both .NET Framework and .NET Core can use .NET Standard libraries in their projects because .NET Standard is the "parent" of both the framework and core. Many newer NuGet packages now release versions that target .NET Standard so the library can be used with both versions. See the below chart to see what version of the .NET Standard library is compatible with various platforms. netstandard libraries are forward compatible so something that is compatible with 1.5 (like .NET 4.6.2) is also compatible with versions 1.0-1.4