Is there any way to run .NET Core Published web application via Kestrel in Local Host?

Viewed 3076

As I know according to Microsoft Docs here in Dotnet core ConfigureWebHostDefaults makes Kestrel default web server inside the project.

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });

So I can use Dotnet Run in my main project path (that contains .sln) and run the project directly with Kestrel without IIS Express and it runs(As I can do that with IIS Express IN VS). But I want to know is there any way to do that in my release production (after Publish) in the local Host in Server? I hosted my project with IIS in server successfully and it works fine but for curiosity, I run Dotnet run in my publish root and it returns:

Welcome to .NET Core 3.1! --------------------- SDK Version: 3.1.404

Telemetry --------- The .NET Core tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

---------------- Explore documentation: https://aka.ms/dotnet-docs Report issues and find source on GitHub: https://github.com/dotnet/core Find out what's new: https://aka.ms/dotnet-whats-new Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs Write your first app: https://aka.ms/first-net-core-app

2 Answers

Once you've built the project, you can use dotnet whatever.dll, the 'run' command is for the source:

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-run

The dotnet run command is used in the context of projects, not built assemblies. If you're trying to run a framework-dependent application DLL instead, you must use dotnet without a command. For example, to run myapp.dll, use:

dotnet myapp.dll

It depends on how your ASP.NET Core app is published. Assuming you don't need to target a specific platform, you could first publish a cross-platform binary and then use dotnet directly on the assembly containing your main program.

As an example, say you have a ASP.NET Core app named MyApp without any specific settings on your MyApp.csproj project file. You can publish it by running dotnet publish -c Release from the MyApp.csproj file path: the published release will contain your app assemblies, including MyApp.dll which contains your main program from where Kestrel is started. From this location, you can run dotnet MyApp.dll to run your ASP.NET Core app.

Related