.Net core and Visual Studio code

.NET Core provides a blazing rapid and modular platform for building server apps, which run on Windows, Mac and Linux. Visual Studio code, with the C# extension could be used to have a powerful editing experience with complete support for C# and debugging.

MOST RECENT OPEN SOURCE TECHNOLOGY

Open source and cross-platform development are integral for the current and future strategies of Microsoft. A lot of building blocks of the .NET stack have become open sourced, while others are developed to embrace and support the new strategy. .NET Core at present is the most recent open source technology for creating cross-platform apps for the web and cloud, which runs on Mac OS X, Linux and Windows.

.NET Core enables writing MVC(Model-View-Controller) apps with C# and relies on .NET Core, the new open source as well as cross-platform modular set of runtimes, compilers and libraries in RC as well. The biggest advantage of .NET Core is that it is entirely independent from any integrated development environment or proprietary project systems, meaning that one could also build an ASP.NET Core app outside Visual Studio.

.Net core and Visual Studio code

USING COMMAND LINE TOOLS

Building an ASP.NET Core application could be accomplished by using several command-line tools to scaffold, create and run apps, while Visual Studio Code could be used for editing. There is plenty of work in progress yet, thus some features may change until it reaches the RTM or Release-to-Manufacturing milestone. For example, ASP.NET Core used to rely on the .NET Execution environment and he command-line interface for building and managing apps. Since .NET Core is created upon .NET Core, DNX would be retire and the CLI would switch to the .NET Core command-line tools for future releases, thus it is important to bear in mind if one wants to start writing cross-platform web applications with ASP.NET Core and C#.

CREATING A SIMPLE DATABASE

The first thing to do is to create a database to work with. One could use an existing database or define the data model with the Entity Framework Code First approach, but support for migrations of code in ASP.NET Core is still in progress and aren’t stable at this time. Thus, one simply creates a new database, which stores a list of car models and the names of the manufacturers.

GETTING STARTED

  1. Installing .NET Core. Whether the OS is Windows, Mac OS or Linux, the instructions for getting .NET core on a machine could be followed. When installation is complete, one should be able to open a command line interface or CMD, PowerShell for Windows, Terminal for both Linux and MacOS and check out if the installation was successful through executing the command: dotnet PowerShell>Output for the dotnet command in PowerShell. The output is the same for Linux and MacOS. At this point, .NET Core has been installed successfully and one could begin building apps.
  2. Creating a .NET Core app using the command line interface. In Windows PowerShell or Linux/MacOS Terminal, one could create a new directory. A new console app could be made using the dotnet new command.
  3. Installing Visual Studio Code. To get IntelliSense working, one should install the C# extension for Visual Studio Code, which also installs OmniSharp for IntelliSense. After it installs, it should be enabled and VS Code should be restarted. At this point, one could open the folder with the earlier VS Code project. This could be done via the command line by using code.
  4. Running in Visual Studio code. To enable debugging and running code from VS Code, a prompt is revealed, asking to add the configuration files. This would add a .vscode folder in the solution root with a couple of .json files-tasks.json and launch.json. The app could be run by proceeding to the Debug pane or pressing Ctrl (Cmd) +Shift+D and then pressing the run button or F5. If everything goes well, one should be able to view the output in the debug console.
  5. Adding classes and navigating through code. At this point, one could start using VS Code to its full potential. IntelliSense, navigating code, code completion and going to definitions. A full list of VS Code tips and tricks could be seen on the official Microsoft GitHub organization.

Getting started with ASP.NET Core and Visual Studio Code is pretty simple and straightforward. One could look forward to everything else in store for the Visual Studio Code. Visual Studio Code goes a step further in running code analytics to locate code issues, which make it less clear, perform worse or adhere to bad practices. Visual Studio could remove all unnecessary using directives from a file. This also handles a lot of things, such as code that is unreachable, case statements and more.

Dive into the .NET Core world and learn how to build easy-to-maintain web apps with Visual Studio Code.

Advertisements