Search code examples
asp.net-core.net-coredotnet-cli

Build and run ASP.NET Core WebAPI using dotnet CLI


I am trying to compile and run a clean ASP.NET Core WebAPI using the dotnet CLI, using both Windows and OS X.

What I´ve tried..

  1. Created new ASP.NET 5 WebAPI using (Yeoman with generator-aspnet, or Visual Studio - I tried both)
  2. dotnet restore, dotnet build (build fails...)

    Project WebApiCoreT (DNXCore,Version=v5.0) will be compiled because some of its inputs were newer than its oldest output. Compiling WebApiCoreT for DNXCore,Version=v5.0 C:\Data\Code\WebApiCore\WebApiCoreT\project.json(9,29): error NU1002: The dependency Microsoft.CodeAnalysis.Common 1.1.0-rc1-20151109-01 does not support framework DNXCore,Version=v5.0. C:\Data\Code\WebApiCore\WebApiCoreT\project.json(9,29): error NU1002: The dependency Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 does not support framework DNXCore,Version=v5.0.

    Compilation failed. 0 Warning(s) 2 Error(s)

    Time elapsed 00:00:01.2486558

  3. dnu restore, dotnet build, dotnet run (build successful, fails at runtime...)

    Project WebApiCoreT (DNXCore,Version=v5.0) will be compiled because some of its inputs were newer than its oldest output. Compiling WebApiCoreT for DNXCore,Version=v5.0

    Compilation succeeded. 0 Warning(s) 0 Error(s)

    Time elapsed 00:00:01.2756028

    Could not resolve coreclr path

As far as I have understood, the dnu, dnx, dnvm toolchain is deprecated and will eventually disappear, but how can I create a WebAPI using the dotnet CLI?

Is there anyway to build anything using the dotnet CLI except for the default "Hello world!" console application?


Solution

  • You will not be able to compile (yet) the application generated by yeoman with the CLI because it generates RC1 (dnx) project templates and references.

    Use the MusicStore sample as a template for how a dotnet web app should look like.