Passing a WebAPI application from .NET Core 2 to .NET Core 3 in 5 +1 (EF) steps
Simple steps:
1. Modiffy in the .csproj <TargetFramework>netcoreapp2.0</TargetFramework> to <TargetFramework>netcoreapp3.1</TargetFramework>
2.Delete <PackageReference Include=”Microsoft.AspNetCore.All” Version=”2.0.8″ />
3. Modify
public static IWebHost BuildWebHost(string[] args) =>
public static IHostBuilder CreateHostBuilder(string[] args) =>WebHost.CreateDefaultBuilder(args)
Host.CreateDefaultBuilder(args).UseStartup<Startup>()
.ConfigureWebHostDefaults(webBuilder =>.Build();
to
public static IHostBuilder CreateHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
Host.CreateDefaultBuilder(args).UseStartup<Startup>()
.ConfigureWebHostDefaults(webBuilder =>.Build();
{webBuilder.UseStartup<Startup>();
});
3. Modify BuildWebHost(args).Run(); to CreateHostBuilder(args).Build().Run();
4. Modify services.AddMvc(); to
services.AddControllers();
services.AddRouting();
5. Modify app.UseMvc(); to
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
6. Optional : modify EF from
<PackageReference Include=”Microsoft.EntityFrameworkCore.SqlServer” Version=”2.1.1″ />
<PackageReference Include=”Microsoft.EntityFrameworkCore.SqlServer” Version=”3.1.3″ /><PackageReference Include=”Microsoft.EntityFrameworkCore.Tools” Version=”2.1.1″ />
<PackageReference Include=”Microsoft.EntityFrameworkCore.Tools” Version=”3.1.3″><PackageReference Include=”Microsoft.VisualStudio.Web.CodeGeneration.Design” Version=”2.1.1″ />
to
<PackageReference Include=”Microsoft.EntityFrameworkCore.SqlServer” Version=”3.1.3″ />
<PackageReference Include=”Microsoft.EntityFrameworkCore.Tools” Version=”2.1.1″ />
<PackageReference Include=”Microsoft.EntityFrameworkCore.Tools” Version=”3.1.3″><PackageReference Include=”Microsoft.VisualStudio.Web.CodeGeneration.Design” Version=”2.1.1″ />
<PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include=”Microsoft.VisualStudio.Web.CodeGeneration.Design” Version=”3.1.2″
Leave a Reply