如何在一个解决方案中的项目之间使用共享资源文件?
我的资源文件有问题。
我有两个项目的解决方案。第一个项目包含 ImageResource.resx
文件以及我使用的图像。此项目中的每个 Form
都可以从设计器访问此文件。但我可以在设计器 ImageResource.resx
文件中看到从第二个项目使用它(存在对第二个项目的引用)。
我已添加 ImageResource.resx
文件作为我的第二个项目的链接。我在设计师身上看到了这一点!但是,当我在第二个项目中使用此资源中的图像时,Visual Studio 修改了我的原始文件(它设置了命名空间和其他..),并且我的解决方案失败了。 Visual Studio 还告诉我,ImageResource.resx
存在于两个 dll 的 first_project.dll
和 second_project.dll
中,
任何人都可以帮我如何正确使用项目间共享资源?
I have a problem with resource files.
I have a solution with two projects. The first project contains ImageResource.resx
file with the images that I use. Every Form
in this project can access this file from the designer. But I can see in the designer ImageResource.resx
file to use it from second project (Reference to second project is present).
I have added the ImageResource.resx
file as a link to my second project. And I saw it in the designer! But when I use an image from this resource in the second project Visual Studio modified my original file (It sets the namespaces, and other..) and my solution breaks. Also Visual Studio tells me that ImageResource.resx
is present in two dll's first_project.dll
and second_project.dll
Can anybody help me with How to correctly use shared resources between projects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
下一步包括将此图标添加到其他项目。请注意重要的区别,您需要将此图标添加为链接!
添加为链接可以避免资源重复。在同一解决方案中创建一个新项目并将其命名为Main。在这个新项目中创建一些文件夹,将其命名为“Resources”(我们目的的逻辑名称)。然后右键单击该文件夹,选择添加现有项目...,然后从共享项目文件夹中选择图像文件。请务必在此处使用添加为链接!如果操作正确,新添加的文件的图标看起来会略有不同(见下文):
添加的资源图标必须如下所示
这些是在项目之间共享图标必须执行的五个简单步骤。你可能会问“这样做有什么好处?”好处是:
Next step consists of adding this icon to the other project(s). Note the important difference, you need to add this icon as a link!
Adding as a link avoids the resource duplication. Create a new Project within the same solution and name it e.g. Main. Create some folder in this new project, naming it Resources (the logical name for our purpose). Then right click on this folder, select Add Existing Item… and choose the image file from the shared project folder. Make sure to use Add As Link here! If done correctly the icon of the newly added file will look slightly different (see below):
Added resource's icon must look like this
These are the five simple steps you must perform to share icons between projects. You might ask "What are the benefits of this?" The benefits are:
这对我不起作用,我找到了另一种(VS2015+)方法。
参见https://stackoverflow.com/a/45471284/4151626
总之,共享项目直接包含到外设中项目。因此,即使 IDE 不支持共享项目中的
元素。可以通过文本编辑器将
元素添加到共享项目中。然后在构建过程中将它们合并到外围项目中。(对超链接表示歉意。为了清楚起见,我只是重新发布答案,但 stackoverflow 编辑器对此进行了严厉打击,删除了重复的答案,以免您受到 ??? 的困扰。)
This didn't work for me and I found another (VS2015+) approach.
See https://stackoverflow.com/a/45471284/4151626
In short, the shared project is directly included into the peripheral project. Thus, even though the IDE does not support
<Resource>
elements in the shared project.<Resource>
elements can be added to the shared project, via a text editor. They are then incorporated into the peripheral project during the build.(Apologies for the hyper-link. I would just repost the answer for clarity, but the stackoverflow editors crack down on this, deleting duplicate answers to save you from ???.)
您可以使用符号链接将文件共享到多个文件夹吗?
视窗:
Can you use a symbolic link to share the file into multiple folders?
windows:
如果资源文件确实在项目之间共享,则应该将其放在共享项目中。
If a resource file is really shared between projects, you should put it in a shared project.
如果该资源不是公开,则您无法看到该资源,并且默认设置为“好友”。您可以在可视化设计器(右上角)中设置“访问修饰符”。
You can't see the resource if it is not public, and it is default set to "Friend". You can set the "Access Modifier" in the Visual Designer (upper right-hand corner).