Yesterday, Microsoft announced about preview release from .Net Core 2 and Visual Studio 2017 preview,
In this topic we will learn:
- Benefits of using .Net Core 2
- How to install visual studio 2017 preview
- How to install .net core 2
- How to create a Hello World web app
- The difference between the .csproj file in .NET Core 2 and .csproj in .Net Core 1.1 With VS 2017 Preview
Some of the benefits of using .NET Core 2 include it has a lot of APIs related to .NET Core 1 and has support for Visual Basic.
Now, let’s go to install them and create "Hello World" from .NET Core 2
Step 1
To install Visual Studio 2017 Preview, click here.
Step 2
Choose the edition which you have license for. If you don’t have license, choose Community Edition.
![.Net Core]()
Step 3
Run the exe and wait for some seconds. Then, choose the following options.
![.Net Core]()
![.Net Core]()
Step 4
Click "Install" and it will look like the follwoing screen where I have VS 2017 and VS 2017 Preview. Both can work side by side without any problem.
![.Net Core]()
When the installation is completed, click "Launch".
![.Net Core]()
Step 5
Select File >> New >> Project then choose ASP.NET Core Web App and press OK.
![.Net Core]()
Step 6
Go to the dropdown list to choose the version of the .NET Core you want.
![.Net Core]()
Ooh! Where is ASP.NET Core 2 ??
So, open the command line and write dotnet –version to see which version you have used now.
![.Net Core]()
The answer to the above question is, ASP.NET Core is a separated download, so click here and download and run the exe.
Step 7
Check the "I agree...." check box and press Install.
![.Net Core]()
![.Net Core]()
Finally, click "Close".
Step 8
Now, open command line and write dotnet –version to see which version you have used.
![.Net Core]()
Step 9
Open Visual Studio and repeat steps 5 and 6. Now, you see ASP.NET Core 2.
![.Net Core]()
Choose it, then choose empty template.
![.Net Core]()
Step 10
Go to Startup.cs and write the following script.
![.Net Core]()
Run the app now. The result should be something like below.
![.Net Core]()
Now, let’s open a csproj file in full template project with .NET core 1.1 and open a csproj file in full template project in .NET Core 2.
Right click on the project and edit csproj. It will look like the following in .NET core 1.1
- <Project Sdk="Microsoft.NET.Sdk.Web">
-
- <PropertyGroup>
- <TargetFramework>netcoreapp1.1</TargetFramework>
- <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
- <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
- <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
- <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
- <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
- <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
- </ItemGroup>
-
- <ItemGroup>
- <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
- </ItemGroup>
- </Project>
But now in .NET Core 2
- <Project Sdk="Microsoft.NET.Sdk.Web">
-
- <PropertyGroup>
- <TargetFramework>netcoreapp2.0</TargetFramework>
- <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
- <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
- <UserSecretsId>aspnet-WebApplication2-19927FA3-AE04-4DE8-A3ED-A8AE9EDD3BF9</UserSecretsId>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final" />
- </ItemGroup>
-
- <ItemGroup>
- <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview1-final" />
- </ItemGroup>
- </Project>
If you look at PackageReference now, it’s just one package called Microsoft.AspNetCore.All. Actually, it’s very short and nice look.