Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running ASP.NET 5 Cross-Platform

Tags:

c#

macos

asp.net

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.

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:

'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

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?

like image 947
Some User Avatar asked Oct 19 '22 12:10

Some User


1 Answers

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.

"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).

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

dnx . kestrel

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

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!

like image 60
mason Avatar answered Oct 22 '22 03:10

mason