command line: execute ASP.Net Core dll with certain profile name

Viewed 2924

Please help me to specify profile name when I'm running ASP.Net Core application using the dotnet WebApplicationLaunchProfile.dll

I use this short form just to have possibility to run the project outside of VS and check how it works.

I know that I can use dotnet run --launch-profile testProfileName however it requires .csproj and .cs source files to be available. I would like to avoid copying source code files and use compiled assemblies. My flow is:

  • build with dotnet build
  • copy build result (bin\Debug folder content) to the separate folder
  • start the dll to use proper profile name using the dotnet WebApplicationLaunchProfile.dll form

However the problem is that

When the app is launched with dotnet run, the first profile with "commandName": "Project" is used

rule from the documentation is not applied if project is executed with dotnet dll command. It is clear that it should not be applied since I'm not using the dotnet run command.

However I'd like to specify profile name somehow.

I've created new ASP.Net Core project from VS template and updated the launchSettings.json file as below:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
...
  "profiles": {
...
    "WebApplicationLaunchProfile": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "weatherforecast",
      "applicationUrl": "https://localhost:4430;http://localhost:8080",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

I've adjusted the profiles:WebApplicationLaunchProfile:applicationUrl value and replaced 5000 and 5001 ports as you can see. Project was uploaded to the https://github.com/oleksabor/curly-broccoli just for quick reference. But there were no modifications besides the launchSettings.json.

I can start the application using the VS or dotnet run command without any problem

However I'm getting error when executing the app with dotnet dll command like below:

C:\projects\WebApplicationLaunchProfile\bin\Debug\netcoreapp3.1>dotnet WebApplicationLaunchProfile.dll                                                     
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.                                                                                                                   
System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.  

I have port 5000 occupied and would like to use 4430 instead.

dotnet WebApplicationLaunchProfile.dll --launch-profile WebApplicationLaunchProfile does not work (error is the same)

Is it possible to set profile name with dotnet dll ?

1 Answers

I would have thought dotnet xxx.dll -launch-profile would work. Did you use the default Program.cs file? (the one generated when we create a project from a template, with Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(...), this is where the configuration magic happens)

Otherwise, you can try setting this environment variable for your process: ASPNETCORE_URLS. It should be picked up and used. More information the github issue page github.com/aspnet/KestrelHttpServer/issues/639. For example: set ASPNETCORE_URLS=https://localhost:4430;http://localhost:8080.

Related