Make sure you have to 2.x SDK installed, CLI command dotnet --list-sdks
- Create a new ASP.NET core webapp project from Visual Studio or CLI -->
dotnet new webapp -o myapp
- Update your .csproj something like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.7" />
</ItemGroup>
</Project>
- Update program.cs to use the older IWebHostBuilder
public class Program
{
public static void Main(string[] args)
=> BuildWebHost(args).Run();
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
=> WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseConfiguration(Configuration)
.Build();
}
- I think you need to add this for razor pages.
// ConfigureServices(IServiceCollection services)
services.AddMvc().AddRazorPagesOptions(async (opt) => await Task.CompletedTask);
// Configure(IApplicationBuilder app, IHostEnvironment env)
app
.UseStaticFiles()
.UseDefaultFiles();
app.UseMvc()
I'm not sure about the razor pages stuff in #4, never used it. But this should probably work.
Here are some guides: