jacksorjacksor (Richard Jackson)
10/03/2023, 6:55 AMdotnet <ApplicationName>.dll
from the published folder ((MS docs)[https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/?view=aspnetcore-6.0#run-the-published-app-locally]) but when creating a fresh project this command is hanging (i.e. not finishing, no console messages).
Steps to reproduce:
- Create new Umbraco v10.7 instance
- Run in debug mode, create a basic homepage
- Publish to folder
- Go to folder, run dotnet <ApplicationName>.dll
- ....wait forever?
All advice greatly appreciated!
Rich
https://cdn.discordapp.com/attachments/1158658538600673311/1158658539024306246/image.png?ex=651d0c5a&is=651bbada&hm=b748e2ce367831c2b18ecb557b653f5d4704bbbb5b0584ff6864ac6ff7e66b15&Ambert
10/03/2023, 7:06 AMdotnet run --project "MyProject"
jacksorjacksor (Richard Jackson)
10/03/2023, 7:48 AMAmbert
10/03/2023, 8:00 AMMike Chambers
10/03/2023, 8:18 AMdotnet publish --no-build --no-restore -c Release /p:EnvironmentName=Development -o ..\..\publish
dotnet exec www.dll --verbosity d
eventually errored in a couple of minutes.. with a failed to bind.. so maybe specify a port?
https://cdn.discordapp.com/attachments/1158658538600673311/1158679451673038868/message.txt?ex=651d1fd4&is=651bce54&hm=bb95c39492d91de9716b63866cb3c92b7e5209ade4cc6fefb3880ad3d7ce5fff&Mike Chambers
10/03/2023, 8:22 AM--urls=https://localhost:44489/
Mike Chambers
10/03/2023, 8:22 AMMike Chambers
10/03/2023, 8:23 AMjson
{"@t":"2023-10-03T08:15:52.7047929Z","@mt":"The HostOptions.BackgroundServiceExceptionBehavior is configured to StopHost. A BackgroundService has thrown an unhandled exception, and the IHost instance is stopping. To avoid this behavior, configure this to Ignore; however the BackgroundService will not be restarted.","@l":"Fatal","@x":"System.OperationCanceledException: The operation was canceled.\r\n at System.Threading.CancellationToken.ThrowOperationCanceledException()\r\n at System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n at Umbraco.Cms.Infrastructure.HostedServices.BackgroundTaskQueue.DequeueAsync(CancellationToken cancellationToken)\r\n at Umbraco.Cms.Infrastructure.HostedServices.QueuedHostedService.BackgroundProcessing(CancellationToken stoppingToken)\r\n at Umbraco.Cms.Infrastructure.HostedServices.QueuedHostedService.ExecuteAsync(CancellationToken stoppingToken)\r\n at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)","EventId":{"Id":10,"Name":"BackgroundServiceStoppingHost"},"SourceContext":"Microsoft.Extensions.Hosting.Internal.Host","ProcessId":49768,"ProcessName":"dotnet","ThreadId":12,"ApplicationId":"43b4f000b61af45719d8ce43246f4c2fe0c7d6c2","MachineName":"MINI-7","Log4NetLevel":"FATAL","EnvironmentName":"Production"}
Mike Chambers
10/03/2023, 8:24 AMMike Chambers
10/03/2023, 8:25 AMdotnet exec www.dll --verbosity d --urls=https://localhost:44489/ -c Release /p:EnvironmentName=Development
D_Inventor
10/03/2023, 8:40 AM.exe
variant of your application present in your publish output folder? I do believe that's the one that you're supposed to be runningMike Chambers
10/03/2023, 8:48 AMMike Chambers
10/03/2023, 8:50 AMMike Chambers
10/03/2023, 8:56 AM.\www.exe urls=https://localhost:44589
same boot failed with the wrong environment name..
{
"@t": "2023-10-03T08:54:22.7270781Z",
"@mt": "The HostOptions.BackgroundServiceExceptionBehavior is configured to StopHost. A BackgroundService has thrown an unhandled exception, and the IHost instance is stopping. To avoid this behavior, configure this to Ignore; however the BackgroundService will not be restarted.",
"@l": "Fatal",
"@x": "System.OperationCanceledException: The operation was canceled.\r\n at System.Threading.CancellationToken.ThrowOperationCanceledException()\r\n at System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n at Umbraco.Cms.Infrastructure.HostedServices.BackgroundTaskQueue.DequeueAsync(CancellationToken cancellationToken)\r\n at Umbraco.Cms.Infrastructure.HostedServices.QueuedHostedService.BackgroundProcessing(CancellationToken stoppingToken)\r\n at Umbraco.Cms.Infrastructure.HostedServices.QueuedHostedService.ExecuteAsync(CancellationToken stoppingToken)\r\n at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)",
"EventId": {
"Id": 10,
"Name": "BackgroundServiceStoppingHost"
},
"SourceContext": "Microsoft.Extensions.Hosting.Internal.Host",
"ProcessId": 29348,
"ProcessName": "www",
"ThreadId": 19,
"ApplicationId": "43b4f000b61af45719d8ce43246f4c2fe0c7d6c2",
"MachineName": "MINI-7",
"Log4NetLevel": "FATAL",
"EnvironmentName": "Production"
}
Mike Chambers
10/03/2023, 9:01 AMMike Chambers
10/03/2023, 9:01 AM.\www.exe urls=https://localhost:44589 --environment Development --configuraton Release
Mike Chambers
10/03/2023, 9:04 AMdotnet www.dll --urls=https://localhost:44589/ --configuration Release --environment Development
Mike Chambers
10/03/2023, 9:04 AMjacksorjacksor (Richard Jackson)
10/03/2023, 9:05 AMMike Chambers
10/03/2023, 9:06 AMBuried in the documentation under Environment variable configuration provider is the following extract:
The default configuration loads environment variables and command-line arguments prefixed with DOTNET_. The DOTNET_ prefix is used by .NET for host and app configuration, but not for user configuration.
So if you use the command line parameter --environment Development that should get transformed into DOTNET_ENVIRONMENT=Development. This was tested as working with a .NET 5.0 worker service.
Mike Chambers
10/03/2023, 9:12 AMlocalhost:5000
as that's the default kestrel port.Sebastiaan
10/03/2023, 9:14 AMSebastiaan
10/03/2023, 9:15 AMMike Chambers
10/03/2023, 9:15 AMdotnet www.dll --urls=https://localhost:44589/ --configuration Release --environment Development
???Sebastiaan
10/03/2023, 9:16 AMSebastiaan
10/03/2023, 9:16 AMjacksorjacksor (Richard Jackson)
10/03/2023, 9:17 AMSebastiaan
10/03/2023, 9:18 AMdotnet www.dll
will automatically run http://localhost:5000
and you can change the port with dotnet run www.dll --urls "http://*:5001"
for port 5001
etc. πMike Chambers
10/03/2023, 9:18 AMdotnet www.dll
give no output.. but dotnet www.dll --urls=https://localhost:44589/ --configuration Release --environment Development
immediately give
https://cdn.discordapp.com/attachments/1158658538600673311/1158694503415296000/image.png?ex=651d2dd9&is=651bdc59&hm=bd9a05613e73713635f7415eb505c0b7584525d6728a9d0689d9b6bc1dd25ac5&Sebastiaan
10/03/2023, 9:18 AM--environment Development
Mike Chambers
10/03/2023, 9:18 AMMike Chambers
10/03/2023, 9:19 AMMike Chambers
10/03/2023, 9:19 AMSebastiaan
10/03/2023, 9:19 AMdotnet www.dll
will suppress any and all output, then you need to dive into log files.Sebastiaan
10/03/2023, 9:20 AMappsettings.development.config
should not apply when you build as Release
Sebastiaan
10/03/2023, 9:20 AM--environment Development
Mike Chambers
10/03/2023, 9:22 AMMike Chambers
10/03/2023, 9:23 AMSebastiaan
10/03/2023, 9:24 AMappconfig.production.config
yeah, but I am not entirely sure about that one what the default is!Mike Chambers
10/03/2023, 9:25 AMdotnet publish --no-build --no-restore -c Debug /p:EnvironmentName=Development -o ..\..\publish
and we'd have a different story..Mike Chambers
10/03/2023, 9:26 AMSebastiaan
10/03/2023, 9:26 AM--no-build --no-restore
as well, it has bitten me before, publishing on local machine and forgetting to do dotnet build
first).Mike Chambers
10/03/2023, 9:28 AMSebastiaan
10/03/2023, 9:28 AMdotnet www.dll
(in the directory where you published the release)
- Go to http://localhost:5000
Note: you will probably get the Umbraco installer starting because the database does not get published.Mike Chambers
10/03/2023, 9:29 AMMike Chambers
10/03/2023, 9:30 AMMike Chambers
10/03/2023, 9:32 AMSebastiaan
10/03/2023, 10:09 AMMike Chambers
10/03/2023, 10:23 AMSebastiaan
10/03/2023, 10:38 AMdotnet publish
will use the appsettings.json which doesn't auto-install.jacksorjacksor (Richard Jackson)
10/03/2023, 10:45 AMdotnet publish
does that use appsettings.json AND appsettings.Production.json?Sebastiaan
10/03/2023, 10:57 AMdotnet publish -c Release -o .\publish
(-o is to set the output directory)
- dotnet www.dll
This actually gave me output as it was doing an automatic install, since I copied appsettings.Development.json
to appsettings.Production.json
I made 1 crucial change in appsettings.Production.json
though and that is Data Source=|DataDirectory|/Umbraco.sqlite.db
to Data Source=|DataDirectory|/Umbraco.sqlite222.db
Then checked ~\publish\umbraco\Data
and found a Umbraco.sqlite222.db
there.
To note: dotnet starts to look at appsettings.Production.json
first, if anything is undefined there, but defined in appsetting.json
then it will pick up from appsetting.json
, I believe environment variables take even more precedence than appsettings.Production.json
but I'm not quite sure. You could check with Diplo God Mode (https://marketplace.umbraco.com/package/diplo.godmode) using "View diagnostics and configuration settings about your Umbraco site and hosting environment" where exactly variables came from.Sebastiaan
10/03/2023, 11:06 AMappsettings.Production.json
? I'd kinda expect appsettings.Release.json
π€·rasmusjp
10/03/2023, 11:15 AMDOTNET_ENVIRONMENT
or ASPNETCORE_ENVIRONMENT
environment variable defines which environment you are running, if not defined it defaults to Production
. ASP.NET Core is by default loading appsettings.json
then appsettings.{environment}.json
if it exists, and then environment variable see https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-7.0 and https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-7.0Mike Chambers
10/03/2023, 1:17 PMuser secrets
too if defined and --environment Development π
that link has https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-7.0#default-application-configuration-sources for priority πMike Chambers
10/03/2023, 1:29 PMrasmusjp
10/03/2023, 1:49 PMDOTNET_ENVIRONMENT
environment variable to whatever you want and load the configuration based on that variable. Also the fact that you can easily override/add where configuration is loaded from makes it so more powerful.Mike Chambers
10/03/2023, 1:53 PMMike Chambers
10/03/2023, 1:55 PMMike Chambers
10/03/2023, 1:58 PMMike Chambers
10/03/2023, 1:58 PMMike Chambers
10/03/2023, 1:59 PMrasmusjp
10/03/2023, 2:02 PMMike Chambers
10/03/2023, 2:23 PMbut either use environment variables to override the settings for each instance
but then that's not really DRY..Mike Chambers
10/03/2023, 2:24 PM