加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core – 在没有Visual Studio 2015的情况下配置.NET Cor

发布时间:2020-12-16 07:02:16 所属栏目:asp.Net 来源:网络整理
导读:我遵循.NET Core RC2文档,大部分信息都是考虑Visual Studio 2015编写的.但是,他们还发布了Visual Studio Code,我也可以从命令行运行应用程序. 当我开发一个我没有VS2015的应用程序时,我无法做到 Hookup launchSettings.json到我的应用程序 更改启动设置,例如
我遵循.NET Core RC2文档,大部分信息都是考虑Visual Studio 2015编写的.但是,他们还发布了Visual Studio Code,我也可以从命令行运行应用程序.

当我开发一个我没有VS2015的应用程序时,我无法做到

> Hookup launchSettings.json到我的应用程序
>更改启动设置,例如托管环境,launchUrl或默认端口5000等.

如果我在没有Visual Studio的情况下开发,如何设置这些属性?

解决方法

在没有Visual Studio的情况下构建.NET Core应用程序绝对是可能的. Visual Studio Code或dotnet CLI可以处理您需要做的所有事情,它只是有点不同.

据我所知,launchSettings.json是特定于Visual Studio的.从documentation:

This file holds settings specific to each profile Visual Studio is configured to use to launch the application,including any environment variables that should be used.

您需要一种不同的方式来设置所需的选项:

绑定地址和端口

在Program.cs中引导应用程序时可以配置此项:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseUrls("http://localhost:8080") // name and port to listen on
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

托管环境

从同一个docs:

ASP.NET Core references a particular environment variable,ASPNETCORE_ENVIRONMENT to describe the environment the application is currently running in. This variable can be set to any value you like,but three values are used by convention: Development,Staging,and Production.

只需为您的平台设置适当的环境变量为“开发”,“暂存”,“生产”等.ASP.NET Core将读取值,所有IHostingEnvironment逻辑都将起作用.

在Windows中,您可以在GUI或命令行中设置环境变量:

setx ASPNETCORE_ENVIRONMENT "Development"

启动网址

在运行应用程序时,Visual Studio会自动打开浏览器,从而尝试提供帮助.如果您使用的是dotnet,则必须手动执行此操作.

我没有尝试过,但Visual Studio Code的这个插件可能会给你这个功能:Visual Studio Chrome Debugger

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读