获得相对路径在C#中链接的资源

编程入门 行业动态 更新时间:2024-10-09 08:30:28
本文介绍了获得相对路径在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:

  • What是各种各样的建设行动在VS.NET项目属性设置和他们做什么?

更多推荐

获得相对路径在C#中链接的资源

本文发布于:2023-05-31 14:01:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/393034.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   链接   资源

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!