I've spent a good hour on toying around with it and I got the "Welcome page" running with it.
As I suspected, you tried to use dotnet-cli with your dnx styled project and you you used the wrong nuget feed (the official one, rather than the nightly myget feeds).
For this demo project, just create a new folder and run dotnet new
. This creates three files: NuGet.Config
, project.json
and Program.cs
. You can delete the later one and just create a Startup.cs
from below.
Startup.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace AspNetCoreCliDemo
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.UseWelcomePage();
}
// This doesn't work right now, as it can't resolve WebApplication type
//public static void Main(string[] args) => WebApplication.Run<Startup>(args);
// Entry point for the application.
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseDefaultConfiguration(args)
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
.UseIISPlatformHandlerUrl()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
project.json:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*",
"Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*"
},
"frameworks": {
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
Note: Only dnxcore
moniker is supported as of now.
Last but not least, the NuGet.Config
that worked in my case:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
I didn't had the success with the two default feeds (api.nuget.org and dotnet-core) as it couldn't resolve a few dependencies. After adding the "cli-deps" feed, all packages were resolved and dotnet run
worked. It will listen on the "http://localhost:5000" port and serve the welcome page.
You may get an error message about having more than one entry point, that's because you got a Main
method in both Program.cs
and Startup.cs
. Just delete the Program.cs
.
This should serve as an entry point.
dotnet-cli
as of now doesn't support commands yet (ones formerly defined in the project.json
file).
dotnet new
command? Seems like your dependencries inproject.json
still refer to rc1. dotnet-cli only works for rc2 nightly builds (no official rc2 build yet) – Tsengproject.json
files and compare the dependencies that differ. dotnet-cli is still in early stage and ASP.NET Core 1.0 in the process of fully migrating to it (hence the delay in ASP.NET Core 1.0 RC2 release, that was supposed to come January). On the official nuget 3 feed there are only the official releases (RC1). It may be that you require newer versions of the dependencies. There is a myget feed at dotnet.myget.org/gallery/cli-deps that contains a more current version of Microsoft.CodeAnalysis.CSharp and the new Microsoft.AspNetCore.Mvc.* packages – Tseng