Search code examples
.netbuildmsbuildargumentscommand-line-interface

Is there a way to pass argument to launchSettings.json in .NET?


I'm using .NET 7 and I have the launchSettings.json file:

{
  "profiles": {
    "http": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "http://localhost:5219;http://10.17.40.77:5219;"
    }
  }
}

I want to change the "applicationUrl" tag by cli when I build the .NET application. Something like: dotnet publish ... --applicationUrl="http://10.17.30.11:5000;, http://11.22.33.44:1000;. Is this possible? I didn't found anything about it other than this question.


Solution

  • In the context of a .NET application, the launchSettings.json file is typically used to configure settings for launching and debugging your application in Visual Studio. This file is not designed to accept command-line arguments directly. However, you can achieve similar functionality by modifying your application code to handle command-line arguments.

    In your application code, you can access command-line arguments using the Environment.GetCommandLineArgs method.