Visual Studio for Mac..NET Standard 2.0 will be missing from the list of available target. 2017 version 15.4 performance project visual studio 2017 visual.
.NET Standard - Demystifying.NET Core and.NET Standard By September 2017 As the newest members of the.NET family, there’s much confusion about.NET Core and.NET Standard and how they differ from the.NET Framework. In this article, I’ll explain exactly what each of these are and look at when you should choose each one. Before going into detail, it’s helpful to look at the larger picture of.NET to see where.NET Core and.NET Standard fit in. When.NET Framework first shipped 15 years ago, it had a single.NET stack that you could use for building Windows desktop and Web applications. Since then, other.NET implementations have emerged, such as Xamarin, which you can use for building mobile apps for iOS and Android, as well as macOS desktop applications, as shown in Figure 1.
Figure 1 The.NET Landscape Here’s how.NET Core and.NET Standard fit into this:.NET Core: This is the latest.NET implementation. It’s open source and available for multiple OSes. With.NET Core, you can build cross-platform console apps and ASP.NET Core Web applications and cloud services.NET Standard: This is the set of fundamental APIs (commonly referred to as base class library or BCL) that all.NET implementations must implement.
By targeting.NET Standard, you can build libraries that you can share across all your.NET apps, no matter on which.NET implementation or OS they run. Introduction to.NET Core.NET Core is a new cross-platform and fully open source.NET implementation that was forked from.NET Framework and Silverlight. It’s optimized for mobile and server workloads by enabling self-contained XCOPY deployments. To get a better feel for.NET Core, let’s take a closer look at what developing for.NET Core looks like.
And let’s do this while exploring the new command line-based tooling. You can also use Visual Studio 2017 for your.NET Core development, but because you’re reading this article, chances are you’re quite familiar with Visual Studio already, so I’ll focus on the new experience. When.NET was created, it was heavily optimized for rapid application development on Windows. In practice, this means that.NET development and Visual Studio were inseparable friends. And sure thing: Using Visual Studio for development is a blast.
It’s super productive and the debugger is hands down the best I’ve ever used. However, there are cases where using Visual Studio isn’t the most convenient option. Let’s say you want to just play with.NET to learn C#: You shouldn’t have to download and install a multi-gigabyte IDE.
Or, say you’re accessing a Linux machine over SSH where using an IDE is simply not an option. Or, say you’re simply someone who prefers using a command-line interface (CLI). That’s why a first-class CLI was created, called.NET Core CLI. The.NET Core CLI’s main driver is called “dotnet.” You can use it for virtually all aspects of your development, including creating, building, testing and packaging projects. Let’s see what this looks like. Start by creating and running a Hello World console app (I use PowerShell on Windows, but this will work equally well with Bash on macOS or Linux).
$ mv Class1.cs HelloWorld.cs Note that you don’t have to update the project file for this change. The new project files used in.NET Core simply include all source files from the project’s directory. Thus, adding, removing and renaming files doesn’t require modifying the project anymore. This makes file operations smoother from the command line. To use the HelloWorld class, you need to update the hello app to reference the logic library. You can do this by editing the project file or by using the dotnet add reference command.
Hello $ cat hello.csproj Exe netcoreapp2.0 As you can see, the logic library has a value for TargetFramework of netstandard2.0, while the console app has a value of netcoreapp2.0. The TargetFramework property indicates which.NET implementation you’re targeting. So, the console app is targeting.NET Core 2.0, while the library is targeting.NET Standard 2.0. That means you can reference the logic library not only from a.NET Core app, but also from an app built for.NET Framework or Xamarin. Unfortunately, most of the libraries available today aren’t targeting.NET Standard, yet. Most of them are targeting the.NET Framework. Of course, not all libraries can (or even should) target.NET Standard.
For instance, a library containing Windows Presentation Foundation (WPF) controls needs to target.NET Framework because UI isn’t part of the standard. However, many of the general-purpose libraries only target.NET Framework because they were created when.NET Standard simply didn’t exist yet. With.NET Standard 2.0, the API set is large enough so that most, if not all, of the general-purpose libraries can target.NET Standard. As a result, 70 percent of all the libraries that exist on NuGet today only use APIs that are now part of.NET Standard.
Still, only a fraction of them are explicitly marked as being compatible with.NET Standard. To unblock developers from using them, a compatibility mode has been added. If you install a NuGet package that doesn’t offer a library for your target framework, nor provides one for.NET Standard, NuGet will try to fall back to.NET Framework. In other words, you can reference.NET Framework libraries as if they were targeting.NET Standard. I’ll show you what this looks like. In my example, I’ll use a popular collection library called PowerCollections, which was written in 2007.
It wasn’t updated in a while and still targets.NET Framework 2.0. I’ll install this from NuGet into the hello app. $ dotnet run hello.csproj: warning NU1701: Package 'Huitian.PowerCollections 1.0.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This may cause compatibility problems. 1 3 2 So, what just happened?
The hello app is targeting.NET Core 2.0. Because.NET Core 2.0 implements.NET Standard 2.0, it also has the compatibility mode for referencing.NET Framework libraries. However, not all.NET Framework libraries will work on all.NET implementations.
For example, they might use Windows Forms or WPF APIs. NuGet has no way of knowing that, so it gives you a warning message so you’re aware of this situation and don’t waste your time troubleshooting issues that might result from this. Note that you’ll get this warning each time you build. This avoids the problem where you simply didn’t see the warning during package installation, or forgot about it. Of course, there’s nothing worse than unactionable warnings that you need to overlook every time you build.
So, the idea here is that after you validate your app, you can then disable the warning for that package. Because the app is running fine (it correctly printed the contents of the bag you created) you can now suppress the warning. To do that, edit the hello.csproj file and add the NoWarn attribute to the package reference. If you now run the app again, the warning should be gone.
Should you install another package that uses the compatibility mode, you’ll get the warning for that package for which you can suppress, as well. The new tooling also lets class library projects produce NuGet packages as part of the build. This makes it much simpler to share your libraries with the world (by pushing to nuget.org) or just within your organization (by pushing to your own package feed on Visual Studio Team Services or MyGet). The new projects also support multi-targeting, which lets you build a single project for multiple.NET implementations. This means you can use conditional compilation (#if) to adapt the library to specific.NET implementations. It also lets you build.NET Standard wrappers for platform-specific APIs. However, all of that is beyond the scope of this article.
Wrapping Up.NET Standard is a specification of APIs that all.NET implementations must provide. It brings consistency to the.NET family and enables you to build libraries you can use from any.NET implementation.
It replaces PCLs for building shared components.NET Core is an implementation of the.NET Standard that’s optimized for building console applications, Web apps and cloud services using ASP.NET Core. Its SDK comes with a powerful tooling that in addition to Visual Studio development supports a full command line-based development workflow. You can learn more about them at.
I just started to develop with Visual Studio 2017 / Xamarin, Target platforms are Android and iOS. I found no reference about whether there is any dependency between the target.net version and the Android/iOS version. Are they completely unrelated, or is there such a table? More details: When I initiate a project, I need to specify a.net framework version, choices range from 2.0 to 4.6.1.
Before I can build it, and to let me specify a correct target for simulation, I need to specify a target Android Version (choices range from 2.1 (API 7) to 8.0 (API 27), there is a similar choice for iOS. Theoretically, since AFAIK Xamarin automatically bundles the compiled app with the.net code (contrary to what happens under Windows, where the.net framework must be installed as a separate system component) any combination ahould work with any target OS, but is this really the case?
Thanx, Armin. The technical details behind would give you a long answer, but it might not be 100% correct. Mono supports multiple.NET profiles, but not the latest If you use Visual Studio for Mac to create a Mono project (console app for example) today (Feb 6, 2018), you should be able to see the newest.NET profile it supports is 4.7 (should be 4.7.0 to match.NET Framework), and C# language is 7.1.
Note on Windows,.NET Framework 4.7.1 is out, and C# 7.2 is supported. Xamarin uses latest Mono The final build of your mobile apps (iOS or Android) would bundle the latest Mono runtime. Thus, the.NET profile and C# compiler you can use would be determined by that Mono version. So in your case today, you should be able to target.NET profile 4.7.0 and C# 7.1. To check, I choose.net 2.0 and compared the choice of platforms with when set to 4.6.1, and both have the same choice of platforms (Android, iOS, and WIndows (UWP)).
Looking deeper into which project types I can choose for each platform, I found no difference between.net 2.0 and 4.6.1. So it seems, that all available.net framework implementations are completely platform independent. Almost too nice to be true:-) aybe I need to install more exotic platforms in addition to the big three to see a difference? – Feb 6 '18 at 15:40.
Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |