Search code examples
c#.net-corereleasewebapidev-to-production

Build/Publish a web .netcore api : I can't access any of my endpoints they returns 500 from postman


I have a .net 5.0 web api application. I want to publish build it to run it on a windows server 2019.

I build it locally in commandline using "dotnet run --launch-profile CMDLINE" CMDLINE is one of my profile in my launchSettings.json

launchsettings.json

I then try to publish my app with the following command.

dotnet publish

I then try "dotnet application.dll" in an attempt to run the dll localy. the application seems to be started but when I try to access my public endpoint (returning a string with tag [Anonymous] doesn't require authentication, then I get the error 500 in postman dotnet application.dll postman result

My project is always compiling in /debug/net5.0/ or in /debug/net5.0/publish/

Am I missing an essential step please help. I basically want to give my build/released application to my system admin, which is going to publish the API on a windows server 2019.

He just told me that running "dotnet application.dll" is not working as expected. (never publish an app on a custom server like this before, always used online hosting.)


Solution

  • I finally noticed my hosting environment wasn't the same as my specified ASPNETCORE_ENVIRONMENT variable in my launchsettings.json! cmd line startup command

    launchsetting

    I simply specified my hosting environment in commandline with "set ASPNETCORE_ENVIRONMENT=Staging" and built it up with "dotnet application.dll --launch-profile CMDLINE" and it worked. "dotnet application.dll" is also working.