Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to Add Add Microsoft Extensions Hosting Manually in .Net Project

How to Add Add Microsoft Extensions Hosting Manually in .Net Project

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netdotnethosting
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12765737
    wrote on last edited by
    #1

    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);
                });
    }
    
    Richard DeemingR 1 Reply Last reply
    0
    • U User 12765737

      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);
                  });
      }
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups