【问题标题】:Build output file path in windows service application在 Windows 服务应用程序中构建输出文件路径
【发布时间】:2014-01-22 19:16:52
【问题描述】:

我有一个在创建时读取文件的 WCF 服务。

我将文件添加到我的项目中,将其 Buid Action 设置为 Content 并将 复制到输出目录 设置为 始终复制,并使用以下内容获取文件路径:

private const string MEDIA_PLAYER_FILENAME = "mediaPlayers.xml";
var mediaPlayerFilePath = Path.Combine(Environment.CurrentDirectory, MEDIA_PLAYER_FILENAME);

当我在控制台应用程序中自行托管它时效果很好,但是当它托管在 Windows 服务中时,它会失败,因为它试图从 C:\Windows\system32\mediaPlayers.xml

我猜Environment.CurrentDirectory 不是我应该使用的那个。应该是什么?还是有其他方法可以做到这一点?

【问题讨论】:

    标签: c# wcf windows-services


    【解决方案1】:

    你想要的是执行程序集的路径。 CurrentDirectory 不是一回事。

    请参阅此帖子以获取该信息:

    Getting the path of the current assembly

    转发:

    (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
    

    或者

    Assembly.GetExecutingAssembly().Location
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-16
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多