Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (66 sloc) 2.54 KB

The .NET CLI

Hello World with the .NET CLI

  1. Install the dotnet CLI for your platform from http://dotnet.github.io/getting-started/

  2. Open a command prompt and navigate to the directory without spaces (This is a known issue) and make a new directory called cliapplication and navigate to it:

mkdir cliapplication
cd cliapplication
  1. Create a new project by typing dotnet new in the cliapplication folder.
  2. Restore packages by typing dotnet restore.
  3. Run the hello world application dotnet run.

Compile and run manually

  1. Run dotnet build
  2. Execute the executable in bin/Debug/dnxcore50 e.g.:
./bin/Debug/dnxcore50/cliaspnet5app

It should print out hello world

Configure the CLI application to use ASP.NET

  1. Edit the NuGet.config in the cliapplication folder and add an entry for the ASP.NET myget feed <add key="aspnet-ci-dev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="aspnet-ci-dev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
  </packageSources>
</configuration>
  1. Add the Microsoft.AspNet.Server.Kestrel package to project.json:
"dependencies": {
  "NETStandard.Library": "1.0.0-rc2-23704",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-*"
},
  1. Run dotnet restore in the project folder to restore packages.
  2. Add a Startup.cs with the following content:
public class Startup
{
    public void Configure(IApplicationBuilder app)
    {
        app.Run(context =>
        {
            return context.Response.WriteAsync("Hello World!");
        });
    }
}
  1. Add code to the Program.cs Main method that boots up ASP.NET.
public static void Main(string[] args)
{
    var app = new WebApplicationBuilder()
                .UseServer("Microsoft.AspNet.Server.Kestrel")
                .UseUrls("http://localhost:5001")
                .UseStartup<Startup>()
                .Build();

    app.Run();
}
  1. Type dotnet run to execute the application. Open a browser and open a browser window to http://localhost:5001, you should see a "Hello World" response.