How to Add Add Microsoft Extensions Hosting Manually in .Net Project
-
I am migrating the .Net Project to .Net core 3.1 and there are loads of dependencies in the project so I cannot create a new .Net core application. How can I add Program.Cs file in my existing .Net api project?
I need this code in my existing .Net api project
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}public static IHostBuilder CreateHostBuilder(string\[\] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }) .UseSerilog((hostingContext, loggerConfiguration) => { var connectionString = hostingContext.Configuration.GetSection("Serilog:WriteTo:0:Args:connectionString"); connectionString.Value = connectionString.Value; loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration); }); }
-
I am migrating the .Net Project to .Net core 3.1 and there are loads of dependencies in the project so I cannot create a new .Net core application. How can I add Program.Cs file in my existing .Net api project?
I need this code in my existing .Net api project
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}public static IHostBuilder CreateHostBuilder(string\[\] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }) .UseSerilog((hostingContext, loggerConfiguration) => { var connectionString = hostingContext.Configuration.GetSection("Serilog:WriteTo:0:Args:connectionString"); connectionString.Value = connectionString.Value; loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration); }); }
If you're migrating, you might want to move to something that will be supported for more than two months:
.NET and .NET Core official support policy[^]:
.NET Core 3.1 End of Support: December 13, 2022
Currently, the "long-term support" (LTS) version is .NET 6.0, which is supported until at least November 12, 2024. Also, you forgot to explain what the problem is with your code. There's nothing obviously wrong with it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer