How to do it...

  1. We will create a .NET Core console application in Visual Studio 2017. Under Visual C# templates, select .NET Core and a Console App (.NET Core) project:
  1. When you created your console application, the code will look as follows:
        using System;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
  1. Modify your code to look as follows:
        static void Main(string[] args)
{
Console.WriteLine("I can run on Windows, Linux and macOS");
GetSystemInfo();
Console.ReadLine();
}

private static void GetSystemInfo()
{
var osInfo = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
Console.WriteLine($"Current OS is: {osInfo}");
}
  1. The method GetSystemInfo() just returns the current operating system the console application currently runs on. The csproj file for my application looks as follows:
        <Project ToolsVersion="15.0"           xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)
Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="***.cs" />
<EmbeddedResource Include="***.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
</Project>

The <version> is defined as 1.1.0.

If you are still running Visual Studio 2017 RC, it would be a good idea to check your installed NuGet packages to see whether there is an update available for your .NET Core version from .NET Core 1.0 to .NET Core 1.1.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.17