我可以使用微软DOTNET CLI打造核心ASP.NET Web应用程序? [英] Can I build ASP.NET Core web application using Microsoft Dotnet CLI?

查看:411
本文介绍了我可以使用微软DOTNET CLI打造核心ASP.NET Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过一些网站消失了,发现.NET的核心是使用 .NET CLI (.NET命令行界面)。我在使用.NET CLI创建控制台应用程序,这是工作的罚款



但是当我创建使用约曼的ASP.NET核心Web应用程序和运行命令DOTNET恢复然后我收到以下错误:



Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01不与DNXCore,版本兼容= V5.0。



我也试过



DOTNET恢复-S <一个HREF =https://api.nuget.org/v3/index.json相对=nofollow> https://api.nuget.org/v3/index.json



但得到同样的错误。



如果我运行DNU恢复,那么它工作正常,所以我的问题是,我可以使用.NET CLI界面,Web应用程序也或只限于?控制台应用程序



我已经通过链接



https://github.com/dotnet/cli &安培; http://dotnet.github.io/getting-started/



但没有找到它支持ASP.NET核心的Web应用程序或没有?


解决方案
<任何细节p>我已经花了上玩弄与它周围的好小时,我得到了欢迎页上的运行状态。



正如我怀疑,你试过用的dotnet-CLI与DNX风格的项目,你使用了错误的NuGet饲料(官方的,而不是每晚myget供稿)。



有关这个示范项目,只需要创建一个新的文件夹,然后运行 DOTNET新。这将创建三个文件: NuGet.Config project.json 的Program.cs 。您可以删除的后一个,只是从下面创建一个 Startup.cs



Startup.cs:

 使用系统; 
使用System.Collections.Generic;
使用System.Linq的;使用System.Threading.Tasks
;
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.AspNetCore.Http;
使用Microsoft.Extensions.DependencyInjection;

命名空间AspNetCoreCliDemo
{
公共类启动
{
//此方法被运行时调用。使用此方法可以服务于容器中添加。
//有关如何配置你的应用程序,请访问http://go.microsoft.com/fwlink/?LinkID=398940
公共无效ConfigureServices(IServiceCollection服务)
{更多信息
}

//此方法被运行时调用。使用此方法来配置HTTP请求管道。
公共无效配置(IApplicationBuilder应用程序)
{
app.UseIISPlatformHandler();
app.UseWelcomePage();
}

//这不,现在的工作,因为它无法解析WebApplication的类型
//公共静态无效的主要(字串[] args)=> WebApplication.Run<&启动GT;(参数);

//入口点的应用程序。
公共静态无效的主要(字串[] args)
{
VAR主机=新WebHostBuilder()
.UseDefaultConfiguration(参数)
.UseServer(Microsoft.AspNetCore .Server.Kestrel)
.UseIISPlatformHandlerUrl()
.UseStartup<&启动GT;()
.Build();

host.Run();
}
}
}



project.json:

  {
版本:1.0.0- *,
compilationOptions:{
emitEntryPoint:真正的
},

依赖:{
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- *
},

框架:{
dnxcore50:{}
},

排除:[
的wwwroot,
node_modules
],
publishExclude:[
**用户,
**。vspscc
]
}

注意: dnxcore 绰号支持截至目前。



最后但并非最不重要的, NuGet.Config ,在我的情况下工作:



<预类=郎咸平的XML prettyprint-覆盖> <?XML版本=1.0编码=UTF-8>?;
<结构>
< packageSources>
<! - 继承全局的NuGet包源中删除的<清/>下面行 - >
<清/>
<添加键=CLI-DEPSVALUE =https://dotnet.myget.org/F/cli-deps/api/v3/index.json/>
<添加键=DOTNET核值=https://dotnet.myget.org/F/dotnet-core/api/v3/index.json/>
<添加键=api.nuget.orgVALUE =https://api.nuget.org/v3/index.json/>
< / packageSources>
< /结构>



我没曾与两个默认饲料的成功(api.nuget.org和dotnet-核心),因为它解决不了几个依赖关系。添加CLI-DEPS饲料后,所有的包都解决, DOTNET运行工作。它会听的的http://本地主机:5000 端口和服务欢迎页面。



您可能会收到关于有多个入口点的错误信息,那是因为你有一个方法无论的Program.cs Startup.cs 。只要删除的Program.cs



这应该作为一个切入点。



DOTNET-CLI 截至目前不支持的命令,但(那些以前在<$ C $定义C> project.json 文件)。


I have gone through some websites and found that .NET Core is using .NET CLI (.NET Command Line Interface). I have create a console application using .NET CLI and it is working fine

But when I am creating an ASP.NET Core web application using Yeoman and running the command "dotnet restore" then I am getting the following error:

Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 is not compatible with DNXCore,Version=v5.0.

I also tried

dotnet restore -s https://api.nuget.org/v3/index.json

But getting the same error.

If I run "dnu restore" then it is working fine so my question is can I use .NET CLI for web application too or it is only limited to console application?

I have gone through the links

https://github.com/dotnet/cli & http://dotnet.github.io/getting-started/

but did not find any details that it supports ASP.NET Core web app or not?

解决方案

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 CLI打造核心ASP.NET Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆