C#:以编程方式将资源文件添加到特定文件夹 [英] C#: Programmatically adding a resource file to a specific folder

查看:88
本文介绍了C#:以编程方式将资源文件添加到特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我正在为Visual Studio 2012制作一个加载项,我的加载项几乎已经完成,但我陷入了一个小部分。所以我的插件基本上创建了一个资源文件并将其添加到项目中。我使用ResXResourceWriter制作资源文件,然后使用DTE对象将资源文件添加到项目中。



这里是我被困的地方:我想将资源文件添加到项目中,但是在特定文件夹中是App_LocalResources文件夹。我的加载项会将文件添加到项目中,但不会添加到该文件夹​​中。有没有办法做到这一点?

Hello everyone! I'm making an add-in for Visual Studio 2012 and my add-in is almost finished but I got stuck in a small section. So my add-in basically creates a resource file and adds it to the project. I used ResXResourceWriter to make the resource file and then I used the DTE object to add the resource file to the project.

Here's where I'm stuck: I want to add the resource file to the project but in a specific folder which is the App_LocalResources folder. My add-in does add the file to the project but not in that folder. Is there a way to do this?

推荐答案

有几种方法可以做到这一点。我描述的是我是如何做的那样。



退出Visual Studio并使用非VS编辑器(例如记事本)编辑xx.csxproj文件。在代码中找到文件引用,只需将任何额外的目录结构添加到filespec中。小心在需要时加倍反斜杠(\\)。如果您愿意,可以将相对目录名称更改为绝对。不要忘记为所有配置执行此操作(例如,调试,发布,...)。



[免责声明:我经常为C ++做这类事情项目文件;希望我已将此正确翻译成C#lingo。]



[更新1]

首先在您的位置创建资源文件选择。将文件添加到项目中。根据文件/文件夹的存在位置,VS将对其进行相对或绝对引用。
There are several ways to do this. What I describe is how I do that kind of thing.

Exit Visual Studio and edit the xx.csxproj file with a non-VS editor (eg. Notepad). Find the file reference in the code and simply add any extra directory structure to the filespec. Be careful to double up backslashes ("\\") where required. You can change relative directory names to absolute if you like. Don't forget to do this for all configurations (eg. Debug, Release, ...).

[disclaimer: I do this type of thing frequently for C++ project files; hopefully I have translated this correctly into C# lingo.]

[Update 1]
Create the resource file first, in the location of your choice. Add the file to the project. Depending on where the file/folder exists, VS will make either a relative or absolute reference to it.


这篇关于C#:以编程方式将资源文件添加到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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