我花了一个小时来玩弄它,并让“欢迎页面”运行起来。
正如我所怀疑的那样,您尝试将 dotnet-cli 与您的 dnx 样式项目一起使用,并且您使用了错误的 nuget 提要(官方提要,而不是每晚的 myget 提要)。
对于这个演示项目,只需创建一个新文件夹并运行dotnet new
. 这将创建三个文件NuGet.Config
:project.json
和Program.cs
。您可以删除后一个,然后Startup.cs
从下面创建一个。
启动.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();
}
}
}
项目.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"
]
}
注意:目前仅dnxcore
支持 moniker。
最后但并非最不重要的NuGet.Config
一点是,在我的情况下有效:
<?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>
我没有成功使用两个默认提要(api.nuget.org 和 dotnet-core),因为它无法解决一些依赖关系。添加“cli-deps”提要后,所有包都已解决并可以正常dotnet run
工作。它将侦听“ http://localhost:5000 ”端口并提供欢迎页面。
您可能会收到有关拥有多个入口点的错误消息,这是因为您在和Main
中都有一个方法。只需删除.Program.cs
Startup.cs
Program.cs
这应该作为一个入口点。
dotnet-cli
截至目前还不支持命令(以前在project.json
文件中定义的命令)。