I work with a code base that contains some code in regular .NET and some code in .NET Core. When I open an individual .cs file, I'm not always sure whether the file was meant to be compiled with regular .NET or .NET Core. Obviously, there's a lot of overlap between both frameworks -- and a lot of code can be run unmodified in both frameworks.
So my question is, what are some easy ways to determine whether a .cs file is intended to be compiled for regular .NET or .NET Core?
(I imagine that looking for certain usings that only exist in one framework or the other is probably the biggest telltale sign. If that is indeed the way to determine this, is there a web page which lists which usings are exclusive to regular .NET vs. .NET Core?)
. Net Core does not support desktop application development and it rather focuses on the web, windows mobile, and windows store. . Net Framework is used for the development of both desktop and web applications as well as it supports windows forms and WPF applications.
NET framework helps you build web apps, desktop apps, and web services. It works only on the Windows operating system. On the other hand, . NET core is for creating cross-platform cloud apps that run on Windows, Mac, and Linux.
Your best bet is to look at the .csproj file.
Look for either the <TargetFramework>
or the <TargetFrameworks>
element. It will have entries such as net461
. You can cross reference with the chart here:
https://docs.microsoft.com/en-us/dotnet/standard/frameworks
Microsoft has a Portability Analyzer that will tell you if your code will run on various platforms and what kind of changes are required, but the only way I know to tell what platform particular code was written for is to check the project properties or makefile.
You could also use an if preprocessor directive such as something like this:
public class MyClass
{
static void Main()
{
#if (NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP2_0 || NETCOREAPP2_1)
<some code>
#else
<some code>
#endif
}
}
I should add that this is a method to use going forward especially with shared code used between NetFramework and Core.
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