-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
The C# Workshop
By :
Visit the VS Code site at https://code.visualstudio.com and download it for Windows, macOS, or Linux, following the installation instructions for your preferred platform.
Note
It is better to check the Create a Desktop Icon checkbox for ease of use.
VS Code is free and open source. It supports multiple languages and needs to be configured for the C# language. Once VS Code is installed, you will need to add the C# for Visual Studio Code (powered by OmniSharp) extension to support C#. This can be found at https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp. To install the C# extension, follow the per-platform instructions:
Extension tab and type C#.Note
If you do not want to directly install the C# extension from the website, install it from VS code itself.
C# for Visual Studio Code (powered by OmniSharp).Install button.VS Code:
Figure 0.1: Installing the C# extension for VS Code
You will see that the C# extension gets successfully installed on VS Code. You have now installed VS Code on your system.
The next section will cover how VS Code can be used as you move between the book chapters.
To change the default project to build (whether it is an activity, exercise, or demo), you will need to point to these exercise files:
tasks.json / tasks.argslaunch.json / configurations.programThere are two different patterns of exercise that you should be aware of. Some exercises have a project of their own. Others have a different main method. The main method of a single project per exercise can be configured like this (in this example for Chapter 3, Delegates, Events, and Lambdas, you are configuring Exercise02 to be the build and launch points):
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Exercises/ /Exercise02/bin/Debug/net6.0/Exercise02.exe",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Chapter05.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
]
}
One project for each exercise (for example, Chapter05 Exercise02) can be configured like this:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net6.0/Chapter05.exe",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Chapter05.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
"-p:StartupObject=Chapter05.Exercises.Exercise02.Program",
],
"problemMatcher": "$msCompile"
},
]
}
Now that you are aware of launch.json and tasks.json, you can proceed to the next section which details the installation of the .NET developer platform.
The .NET developer platform can be downloaded from https://dotnet.microsoft.com/download. There are variants for Windows, macOS, and Docker on Linux. The C# Workshop book uses .NET 6.0.
Follow the steps to install the .NET 6.0 platform on Windows:
Windows platform tab:
Figure 0.2: .NET 6.0 download window
Download .NET SDK x64 option.Note
The screen shown in Figure 0.2 may change depending on the latest release from Microsoft.
Follow the steps to install the .NET 6.0 platform on macOS:
macOS platform tab (Figure 0.2).Download .NET SDK x64 option.After the download is complete, open the installer file. You should have a screen similar to Figure 0.3:
Figure 0.3: The macOS installation starting screen
Continue button.The following screen will confirm the amount of space that will be required for the installation:
Install button to continue:
Figure 0.4: Window displaying the disk space required for installation
You will see a progress bar moving on the next screen:
Figure 0.5: Window showing the Installation progress
Soon after the installation is finalized, you'll have a success screen (Figure 0.6):
Figure 0.6: Window showing the installation as complete
dotnet –list-sdks
This will check the version of .NET installed on your machine. Figure 0.7 shows the output where your installed SDKs will be listed:
Figure 0.7: Checking the installed .NET SDKs in Terminal
With these steps, you can install the .NET 6.0 SDK on your machine and check the installed version.
Note
Net 6.0 installation steps for Linux are not included as they are like Windows and macOS.
Before proceeding further, it is important to know about .NET 6.0 features.
With .NET 6.0 installed on your system, the next step is to configure projects using CLI.
Change the font size
Change margin width
Change background colour