ASP.NET 5 With Visual Studio Code: Part 2

aspnet

This article is a part of article series on ASP.NET 5 with Visual Studio Code. In last article I discussed about ASP.NET 5, Node.js, YEOMAN & Visual Studio Code. I will also discuss about Gulp, Grunt, Bower in further articles but not in this post.

If you missed previous article you can go through the following link:

After writing the first article of the series I felt that beginners and some intermediate level readers are not aware about installing ASP.NET 5, DNVM & DNX, so I am going to explain it.

  • Installing ASP.NET 5

Go to the URL.

url

Click on Get ASP.NET button. It will redirect to anew page ( get.asp.net/ ),

new

Click on Install for Windows for ASP.NET 5 RC.

If you want to install it for other OS (Linux or Mac OSX) click on Other Downloads.

os

It will redirect you to a new page from where you can choose it for Windows, OS X or Linux.

downloads

I have downloaded it for Windows. It will install ASP.NET 5 RC for windows.

setup

Installing the DNVM (.NET Version Manager)

.NET Version Manger (DNVM) is a command line utility which is used to configure and update .NET Execution Environment (DNX). To install & update it use the following steps:

Windows:

Open command prompt and run the following,

  1. @powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{iex ((new-object net.webclient).DownloadString('https://dist.asp.net/dnvm/dnvminstall.ps1'))}"  
Linux or OS X

Open a terminal and run the following,

curl -sSL https://dist.asp.net/dnvm/dnvminstall.sh | sh && source ~/.dnx/dnvm/dnvm.sh

Installing .NET Execution Environment (DNX)
 
dnvm install latest

DNVM commands

Command Name Details
alias Lists and manages alias.
exec Executes the specified command in a sub-shell where the PATH has been augmented to include the specified DNX.
help Displays a list of commands, and help for specific commands.
install Installs a version of the runtime.
list Lists available runtimes.
run Locates the dnx.exe for the specified version or alias and executes it, providing the remaining arguments to dnx.exe
setup Installs the version manager into your User profile directory.
uninstall Uninstalls a version of the runtime.
update-self Updates DNVM to the latest version.
upgrade Installs the latest version of the runtime and reassigns the specified alias to point at it.
use Adds a runtime to the PATH environment variable for your current shell.
version Displays the DNVM version.

You can also see the above list of commands by writing DNVM on command prompt.

If some commands failed to execute due to permission then you can open command prompt with administrative right.

admin

Creating different types of application using Visual Studio Code

To see the list of application which can be created using Visual Studio code run the following command of command prompt:,

yo aspnet

cmd

As you can see in the above screen it is saying that update is available and it is also suggesting the command to upgrade it.

The command to update Yeoman is : “npm install –g yo”.

After running this command it will take a few minutes to update the latest version of Yeoman. My current version for Yeoman is 1.5.0 and after running the above command it will be upgraded to 1.5.1.

Here I am using –g in the command to say that install it globally. If you are not aware about installing it then please have a look at my previous article.

Using “yo aspnet” command we can create the following types of applications,
  1. Empty Application
  2. Console Application
  3. Web Application
  4. Web Application Basic [without Membership and Authorization]
  5. Web API Application
  6. Nancy ASP.NET Application
  7. Class Library
  8. Unit test project

To create an application we have to choose the type of application listed above. Then provide the name of the application.

Empty Application

Type “yo aspnet” on command prompt and select Empty Application,

Empty

In case of empty application very few files are created and they are:

  1. bin directory
  2. wwwroot directory
  3. gitignore
  4. Dockerfile
  5. project.json
  6. project.lock.json
  7. Startup.cs

To run it just 4 steps are required:

  1. cd “MyFirstEmptyApplication”
  2. dnx restore
  3. dnu build (optional, build will also happen when it’s run)
  4. dnx web

cmd

Console Application

Type “yo aspnet” on command prompt and select “Console Application

cmd

Provide the name of console application “ConsoleApplicationDemo”,

cmd

To run it use dnx consoleApplicationDemo,

cmd

In the same way you can create other types of application too.

Let me explain about the commands listed above:

  1. cd “consoleApplicationDemo” – As we know that this a basic command of console for changing a directory.
  2. dnu restore
  3. dnu build

DNU - .NET Development Utilities

.NET Development Utilities (DNU) is a command-line tool which is used for variety of utility functions in ASP.NET. We can use DNU for building application for managing dependencies. It also take care about Nuget packages.

In the above case “dnu restore” will be used for downloading all the dependencies for the project. And "dnu build" will be used for building the application and displaying the output on console.

All the available commands for DNU are:

DNU Commands

Command Details
build Produce assemblies for the project in given directory.
clear-http-cache Clears the package cache.
commands Commands related to managing application commands (install, uninstall).
feeds Commands related to managing package feeds currently in use.
install Install the given dependency.
list Print the dependencies of a given project.
pack Build NuGet packages for the project in given directory.
packages Commands related to managing local and remote packages folders.
publish Publish application for deployment.
wrap Wrap a csproj/assembly into a project.json, which can be referenced by project.json files.


DNX Options

Options Details
--project|-p <PATH> Path to the project.json file or the application folder. Defaults to the current folder if not provided.
--appbase <PATH> Application base directory path.
--lib <LIB_PATHS> Paths used for library look-up.
--debug Waits for the debugger to attach before beginning execution.
--bootstrapper-debug Waits for the debugger to attach before bootstrapping runtime.
--framework <FRAMEWORK_ID> Set the framework version to use when running (i.e. dnx451, dnx452, dnx46, ...)
-?|-h|--help Show help information
--version Show version information
--watch Watch file changes
--packages<PACKAGE_DIR> Directory containing packages
--configuration<CONFIGURATION > The configuration to run under
--port <PORT> The port to the compilation server


Similar Articles