运行ASP.NET 5跨平台

时间:2021-09-02 12:28:41

I'm interested in ASP.NET 5 on my Windows and Mac OS machines. To get started, I installed Visual Studio 2015 RC on my Windows machine. I created a new, empty web site for ASP.NET 5 (aka vNext). I updated the template with a Views directory and included the MVC and Static Files nuget packages. I can successfully run this "Hello World" app. I also was successful in checking it into GitHub and automatically deploying it to Azure as a Website.

我对Windows和Mac OS机器上的ASP.NET 5很感兴趣。首先,我在Windows机器上安装了Visual Studio 2015 RC。我为ASP.NET 5(又名vNext)创建了一个新的空网站。我使用Views目录更新了模板,并包含了MVC和Static Files nuget包。我可以成功运行这个“Hello World”应用程序。我也成功地将其检入GitHub并自动将其部署到Azure作为网站。

Then, I cloned the repository on my Mac OS machine. I successfully ran dnu restore to get the packages. I then ran dnx . run. When I do this, I get an error though. The error is:

然后,我在Mac OS机器上克隆了存储库。我成功运行dnu restore来获取软件包。然后我跑了dnx。跑。当我这样做时,我收到了一个错误。错误是:

'Website' does not contain a static 'Main' method suitable for an entry point

What am I doing wrong? I have a Startup.cs file. I know it works based on the fact that it runs on Windows and in Azure. Yet, I can't figure out what I'm missing. My Startup.cs file looks like this:

我究竟做错了什么?我有一个Startup.cs文件。我知道它的工作原理是它在Windows和Azure上运行。然而,我无法弄清楚我错过了什么。我的Startup.cs文件如下所示:

Startup.cs

Startup.cs

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;

namespace Test.Site.Web
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app)
        {
            app.UseErrorPage();
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute("default",
                  "{controller}/{action}/{id}",
                  defaults: new { controller = "Home", action = "Index" });
            });

            app.UseMvc();
            app.UseWelcomePage();
        }
    }
}

What did I do wrong?

我做错了什么?

1 个解决方案

#1


3  

In your project.json file, there should be a set of commands to run the project. By default, one of those is web and one is kestrel. Kestrel is the server for OS X and Linux, it's based on libuv, the same library that powers Node.

在project.json文件中,应该有一组命令来运行项目。默认情况下,其中一个是web,一个是kestrel。 Kestrel是OS X和Linux的服务器,它基于libuv,它是为Node提供动力的同一个库。

"commands": {
    "gen": "Microsoft.Framework.CodeGeneration",
    "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004",
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002"
},

(I don't have VS 2015 in front of me at the moment, so I'm not 100% sure of the default commands in an "empty" project, so you may need to add the kestrel command).

(我目前没有VS 2015在我面前,所以我不能100%确定“空”项目中的默认命令,因此您可能需要添加kestrel命令)。

So run this command to start your server on OS X or Linux:

因此,运行此命令可在OS X或Linux上启动服务器:

dnx . kestrel

If you were starting it from the command prompt on Windows, you'd use:

如果从Windows上的命令提示符启动它,则使用:

dnx . web

Note you can customize the commands however you like. For example, one command might generate the database. Another might analyze the server for system requirements. One might even uninstall the application!

请注意,您可以根据需要自定义命令。例如,一个命令可能会生成数据库。另一个可能会分析服务器的系统要求。有人甚至可以卸载应用程序!

#1


3  

In your project.json file, there should be a set of commands to run the project. By default, one of those is web and one is kestrel. Kestrel is the server for OS X and Linux, it's based on libuv, the same library that powers Node.

在project.json文件中,应该有一组命令来运行项目。默认情况下,其中一个是web,一个是kestrel。 Kestrel是OS X和Linux的服务器,它基于libuv,它是为Node提供动力的同一个库。

"commands": {
    "gen": "Microsoft.Framework.CodeGeneration",
    "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004",
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002"
},

(I don't have VS 2015 in front of me at the moment, so I'm not 100% sure of the default commands in an "empty" project, so you may need to add the kestrel command).

(我目前没有VS 2015在我面前,所以我不能100%确定“空”项目中的默认命令,因此您可能需要添加kestrel命令)。

So run this command to start your server on OS X or Linux:

因此,运行此命令可在OS X或Linux上启动服务器:

dnx . kestrel

If you were starting it from the command prompt on Windows, you'd use:

如果从Windows上的命令提示符启动它,则使用:

dnx . web

Note you can customize the commands however you like. For example, one command might generate the database. Another might analyze the server for system requirements. One might even uninstall the application!

请注意,您可以根据需要自定义命令。例如,一个命令可能会生成数据库。另一个可能会分析服务器的系统要求。有人甚至可以卸载应用程序!