1: Open the CLI
Run it:
dotnet new --list
Copy the code
Create a project from the template
dotnet new console -n helloword
Copy the code
So take a look at the solution helloWord.csproj created by Dotnet Core
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp31.</TargetFramework>
</PropertyGroup>
</Project>
Copy the code
Modified to
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp31.</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>
Copy the code
Run the following command to generate the EXE file
dotnet build
Copy the code
Execute the command to start the program
dotnet run
Copy the code
Modify the console application to web execution
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp31.</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>
</Project>
Copy the code
Modify console program
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
using System;
namespace helloword
{
class Program
{
static void Main(string[] args)
{
WebHost.CreateDefaultBuilder().UseKestrel().Configure(app => app.Run(
context => context.Response.WriteAsync("hello word!") )).Build().Run(); }}}Copy the code
Continue to start program
This enables web startup