Click here to Skip to main content
16,020,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 api project

C#
<pre>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<Startup>();
            })
            .UseSerilog((hostingContext, loggerConfiguration) =>
            {
                var connectionString = hostingContext.Configuration.GetSection("Serilog:WriteTo:0:Args:connectionString");
                connectionString.Value = connectionString.Value;
                loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration);
            });
}


What I have tried:

C#
<pre>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<Startup>();
            })
            .UseSerilog((hostingContext, loggerConfiguration) =>
            {
                var connectionString = hostingContext.Configuration.GetSection("Serilog:WriteTo:0:Args:connectionString");
                connectionString.Value = connectionString.Value;
                loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration);
            });
}
Posted
Comments
Graeme_Grant 19-Oct-22 4:19am    
I'm not understanding your question.

1. What type of app are you porting?
2. Your code dump suggests that you want to use IOC & DI.
3. ConfigureWebHostDefaults suggests that your building a web app. Is that correct?
4. IF you're porting to Dot Net Core, then why 3.1 and not 6.0? 7.0 will be released next month.

Does your app that you are porting ready for this?


ref: One Month to GA: .NET 7 Release Candidate 2 Ships -- Visual Studio Magazine[^]
Richard Deeming 19-Oct-22 7:42am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900