将Visual Studio资源文件放置在“资源"以外的文件夹中? [英] Place Visual Studio resource files in a folder other than 'Resources'?

查看:644
本文介绍了将Visual Studio资源文件放置在“资源"以外的文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为rs.resx的资源文件.在Visual Studio设计器中,我可以通过单击添加资源"并指定图像文件的路径来将图像添加到资源文件中.

添加图像后,图像文件本身也被复制到我的Visual Studio解决方案中名为Resources的文件夹中.我希望将所有图像文件放置在名为Images的文件夹中.这可能吗?

解决方案

这有些棘手,但有可能.

VS检查添加到资源的文件是否已在项目中的某个位置定义.如果找不到它,它将创建资源文件夹,在其中放置一个副本到该文件,将该文件添加到项目中,并在资源设计器中添加对该文件的新副本的引用.

为避免这种情况,您应该先将文件添加到项目中,然后再将其添加到资源文件中.如果文件不在项目结构中,则可以创建一个文件夹,右键单击它,选择添加文件,然后单击OpenFileDialog的添加按钮,请按按钮旁边的小箭头,然后选择添加为链接.

现在,文件位于您想要的硬盘上的任何位置,并且如果现在在资源设计器中添加文件,则资源设计器不会在项目文件中创建副本.

也许这张小图片有助于找到添加为链接按钮:
(来源: modbusdriver.com )

I have a resource file named rs.resx. In the Visual Studio designer, I can add an image to my resource file by clicking "Add resource" and specifying the path to my image file.

After adding the image, the image file itself is also copied to a folder in my Visual Studio solution named Resources. I would like all of my image files to be placed in a folder named Images instead. Is this possible?

解决方案

This is a little tricky, but it is possible.

VS checks if the file added to a resource is already defined somewhere within your project. If it can't find it, it creates the folder Resources, puts a copy to the file there, adds this file to the project and puts a reference into the resource designer to this fresh copy of your file.

To avoid this behaviour you should add the file to your project before you add it into the resource file. If the file isn't somewhere within your project structure you can just create a folder, right click it, select Add file and before you click on the Add button of the OpenFileDialog, push on the little arrow next to the button and select Add as link.

Now the file resides on the place on your hdd wherever you like and the resource designer doesn't create a copy within your project file if you now add the file within the resource designer.

Maybe this little picture helps to find the Add as link button:
(source: modbusdriver.com)

这篇关于将Visual Studio资源文件放置在“资源"以外的文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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