Saturday, July 22, 2017

Using .NET Standard 2.0.0 preview in Visual Studio

.NET Standard is the new common library for all .NET platforms (.NET Framework, .NET Core, Xamarin). There is a good introduction on the .NET Blog (https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/).
You can create a new .NET Standard project within Visual Studio 2017. Click on "Create new project...". Then you can select the .NET Standard entry to create a Class Library (.NET Standard). As .NET Framework you can choose a version equal or greater than 4.6.1 to support .NET Standard 2.0.



After creating the project, you can see under Dependencies the NETStandard.Library.



You can choose "Manage NuGet Packages..." from the context menu to have a closer look. You can see that version 1.6.1 is used, since it is the latest stable version that is compatible with the .NET Framework 4.7.



Furthermore you can see the messages "Blocked by project" and "Following versions are unavailable due to additional constraints in the project or packages.config" for version 2.0.0-preview2-25401-01 and some others.

Following entries can you see in the project file.
<Project Sdk="Microsoft.NET.Sdk"> 
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup> 
</Project>

Nevertheless you can install the 2.0 version via Package Manager Console. Just enter

Install-Package NETStandard.Library -IncludePrerelease -Version 2.0.0-preview2-25401-01

If you look again in the project file, you will see 3 lines that were added.
<Project Sdk="Microsoft.NET.Sdk"> 
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup> 
  <ItemGroup>
    <PackageReference Update="NETStandard.Library" Version="2.0.0-preview2-25401-01" />
  </ItemGroup> 
</Project>

But this will not solve the problem. .NETStandard 2.0 is not used properly. In Visual Studio 15.2 you can not choose .NERStandard 2.0.



It is supported with Visual Studio 15.3.






<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>

No comments:

Post a Comment