diff --git a/aspnetcore/host-and-deploy/windows-service/samples/2.x/AspNetCoreService/Program.cs b/aspnetcore/host-and-deploy/windows-service/samples/2.x/AspNetCoreService/Program.cs index aac5fec378..c86d760e68 100644 --- a/aspnetcore/host-and-deploy/windows-service/samples/2.x/AspNetCoreService/Program.cs +++ b/aspnetcore/host-and-deploy/windows-service/samples/2.x/AspNetCoreService/Program.cs @@ -15,16 +15,17 @@ namespace SampleApp public static void Main(string[] args) { var isService = !(Debugger.IsAttached || args.Contains("--console")); - var builder = CreateWebHostBuilder( - args.Where(arg => arg != "--console").ToArray()); - + if (isService) { var pathToExe = Process.GetCurrentProcess().MainModule.FileName; var pathToContentRoot = Path.GetDirectoryName(pathToExe); - builder.UseContentRoot(pathToContentRoot); + Directory.SetCurrentDirectory(pathToContentRoot); } + var builder = CreateWebHostBuilder( + args.Where(arg => arg != "--console").ToArray()); + var host = builder.Build(); if (isService)