appsettings.json启动.NET核心Windows服务时未读取

发布于 2025-02-09 00:09:07 字数 386 浏览 2 评论 0原文

我关注Microsoft 指南。

从Visual Studio或命令行运行时,AppSettings.json文件将被读取,但是当服务Manager执行服务DLL时,它会失败。

从配置中填充的所有变量保持空为空。

问题是Windows Service Manager将默认目录设置为c:\ Windows \ System32

如何从安装路径中阅读?

I follow the Microsoft guide to build a Windows service.

The appSettings.json file is read when running from the Visual Studio or command line, but when the service DLL is executed from the Service Manager, it fails.

All variables populated from config remain empty remain empty.

The problem is that Windows Service Manager set the default directory to c:\windows\system32.

How to read from installation path?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光磨忆 2025-02-16 00:09:07

在Service Startup,将工作路径设置为以这种方式设置安装路径:

//program.cs
IHost host = Host.CreateDefaultBuilder(args)
  .ConfigureAppConfiguration(conf =>
  {
      conf.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
  })
  ...

此修改确保将工作路径设置为安装路径,从而在服务管理器执行服务时可以正确访问配置文件。

At service startup, set the working path to the installation path this way:

//program.cs
IHost host = Host.CreateDefaultBuilder(args)
  .ConfigureAppConfiguration(conf =>
  {
      conf.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
  })
  ...

This modification ensures that the working path is set to the installation path, allowing proper access to configuration files when the service is executed from the Service Manager.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文