获得相对路径在C#中链接的资源 [英] Get Relative Path to Linked Resource in C#

查看:438
本文介绍了获得相对路径在C#中链接的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些链接资源(在这种情况下,文本文件),在C#项目我的工作。我知道资源是通过在资源文件中的相对路径链接。有没有什么办法让从C#code是相对路径?

I have a number of linked resources (text files in this case) in a C# project I am working on. I know the resources are linked via relative path in the Resources file. Is there any way to get that relative path from within the C# code?

如果没有,我所试图做的是要通过资源文件到外部应用程序作为命令行参数。如果我不能做到这一点的第一种方式(这显然是最简单的)任何其他建议将是非常美联社preciated。谢谢!

If there isn't, what I am trying to do is to pass that resources file to an external application as a commandline argument. If I can't do it the first way (which would obviously be the easiest) any other suggestions would be much appreciated. Thanks!

推荐答案

编译后的资源文件是一个DLL的一部分。因此,他们不会在你分发文件系统存在了。如果你需要有资源文件作为的ressource然后Hueso的解决方案是通过文件到外部应用程序的唯一途径。

After compilation the resource files are part of a dll. So they do not exist anymore in the file system you distribute. If you need to have the resource files as a ressource then Hueso's solution is the only way of passing the files on to an external application.

不过,如果你不介意的文件,由你可以设置的BuildAction 内容的用户可以访问并设置复制到输出目录是否有更新复制总是。然后文件被复制到输出的目录,并且可以从那里进行访问。如果文件在子文件夹,这些子文件夹也被复制到输出目录。

However, if you don't mind the files being accessible by the user you can set the BuildAction to Content and set the Copy to Output Directory to either Copy if newer or Copy always. The files are then copied into the output directory and can be accessed from there. If the files are in sub folders these subfolders are also copied into the output directory.

编辑:

有关的各项建设行动及其效果看:

For the various build actions and their effect see:

  • <一个href="http://stackoverflow.com/questions/145752/what-are-the-various-build-action-settings-in-vs-net-project-properties-and-wha">What是各种各样的建设行动在VS.NET项目属性设置和他们做什么?

这篇关于获得相对路径在C#中链接的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆