微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-core – 在没有Visual Studio 2015的情况下配置.NET Core Web应用程序启动设置

我遵循.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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐