asp.net-corevisual-studio-code.net-core.net-core-rc2

Configuring .NET Core web application launch settings without Visual Studio 2015


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

  1. Hookup launchSettings.json to my application
  2. Change the launch settings e.g. Hosting Environment, launchUrl, or default port 5000, etc.

How do I set these properties if I am developing without Visual Studio?


Solution

  • 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, and Production.

    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