I am following the .NET Core RC2 documentation and most of the information is written considering Visual Studio 2015. However, they also released Visual Studio Code and I can also run applications from the command line.
When I develop a application where I don't have VS2015, I am unable to
launchSettings.json
to my applicationHosting Environment
, launchUrl
, or default port 5000
, etc.How do I set these properties if I am developing without Visual Studio?
The launchSettings. json file is used to store the configuration information, which describes how to start the ASP.NET Core application, using Visual Studio. The file is used only during the development of the application using Visual Studio. It contains only those settings that required to run the application.
It's definitely possible to build a .NET Core app without Visual Studio. Visual Studio Code or the dotnet
CLI can handle everything you need to do, it's just a little different.
As far as I can tell, launchSettings.json
is Visual Studio-specific. From the 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.
You'll need a different way of setting the options you want:
Binding address and port
This can be configured when you bootstrap your application in 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();
}
Hosting environment
From the same 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
, andProduction
.
Just set the appropriate environment variable for your platform to "Development", "Staging", "Production", etc. ASP.NET Core will read the value and all the IHostingEnvironment
logic will work.
In Windows, you can set environment variables in the GUI or on the command line:
setx ASPNETCORE_ENVIRONMENT "Development"
Launch URL
Visual Studio tries to be helpful by opening the browser automatically for you when you run your application. If you're using dotnet
, you'll have to do this manually.
I haven't tried it, but this plugin for Visual Studio Code might give you that functionality: Visual Studio Chrome Debugger
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With