On November 16th, Microsoft announced the .NET Core Tools MSBuild"alpha". I’ve been developing .Net Core applications with Visual Studio Code for a while now, and I needed to try the new tooling.
In this post I’ll show you which were my First steps with .NET Core Tools MSBuild “alpha”
Installing .NET Core SDK 1.0 Preview 3 build 004056
The first step was to install the new tools from: .NET Core SDK 1.0 Preview 3 build 004056
Creating a Sample Console Application
Open a command prompt and run the following commands
1 md test.msbuild
2 cd test.msbuild
3 dotnet new
4 code .
Surprise Code shows two files and one is test.msbuild.csproj. Bye bye project.json!!!
There is no Intellisense for csproj files
This will make things difficult for a while but right now you have to forget about Intellisense and Autocomplete on your csproj file, which makes adding references a real pain.
The csproj file does not target .Net Core 1.1 by default
You’ll have to edit the csproj file to target .Net Core 1.1 (lines 6 and 16)
1<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
3
4 <PropertyGroup>
5 <OutputType>Exe</OutputType>
6 <TargetFramework>netcoreapp1.1</TargetFramework>
7 </PropertyGroup>
8
9 <ItemGroup>
10 <Compile Include="**\*.cs" />
11 <EmbeddedResource Include="**\*.resx" />
12 </ItemGroup>
13
14 <ItemGroup>
15 <PackageReference Include="Microsoft.NETCore.App">
16 <Version>1.1.0</Version>
17 </PackageReference>
18 <PackageReference Include="Microsoft.NET.Sdk">
19 <Version>1.0.0-alpha-20161104-2</Version>
20 <PrivateAssets>All</PrivateAssets>
21 </PackageReference>
22 </ItemGroup>
23
24 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
25</Project>
Create launch.json
Hit F5 and select .NET Core. Visual Studio Code will create a launch.json file and because the tooling is not yet fully supported you’ll have to edit the file manually with the following values
1{
2 "version": "0.2.0",
3 "configurations": [
4 {
5 "name": ".NET Core Launch (console)",
6 "type": "coreclr",
7 "request": "launch",
8 "preLaunchTask": "build",
9 "program": "${workspaceRoot}/bin/Debug/netcoreapp1.1/test.msbuild.dll",
10 "args": [],
11 "cwd": "${workspaceRoot}",
12 "stopAtEntry": false,
13 "externalConsole": false
14 },
15 {
16 "name": ".NET Core Attach",
17 "type": "coreclr",
18 "request": "attach",
19 "processId": "${command.pickProcess}"
20 }
21 ]
22}
Create task.json
Hit F5 again and select .NET Core. Visual Studio Code will create a task.json file which you won’t have to modify.
1{
2 // See https://go.microsoft.com/fwlink/?LinkId=733558
3 // for the documentation about the tasks.json format
4 "version": "0.1.0",
5 "command": "dotnet",
6 "isShellCommand": true,
7 "args": [],
8 "tasks": [
9 {
10 "taskName": "build",
11 "args": [ ],
12 "isBuildCommand": true,
13 "showOutput": "silent",
14 "problemMatcher": "$msCompile"
15 }
16 ]
17}
Restore packages
Run the following command from the Visual Studio Code terminal or the command prompt from step 1
1 dotnet restore
Visual Studio Code won’t prompt automatically to restore so failing to run this step manually will prevent you from building the application.
Run and debug the application
Place a break point in line 7 of the Program.cs file
1using System;
2
3class Program
4{
5 static void Main(string[] args)
6 {
7 Console.WriteLine("Hello World!");
8 }
9}
Hit F5 and the program should stop at the break point and you are good to go!
Side by side with project.json tooling (no migration)
To be able to run my applications based on the project.json tools I had to add a global.json file in the root folder, with the following content
1{
2 "sdk": {
3 "version": "1.0.0-preview2-1-003177"
4 }
5}
If you are not sure of which versions you have installed, just run the following powershell command:
1ls $env:programfiles\dotnet\sdk
And change the value in the global.json file as desired.
Hope it helps!
Comments