Yuriy Yuriy - 1 year ago 117
C# Question

How to use shared resource file between projects in one solution?

I have a problem with resource files.

I have a solution with two projects. The first project contains

file with my images what I use. Every
in this project can access this file from designer. But I can see in the designer
file to use it from second project (Reference to second project is present).

I have added the
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
is present in two dll's

Can anybody help me with How to correctly use shared resources between projects?

Answer Source

1.The correct way in sharing some resources consist in creation of the global shared project. Create new Project with name Resources;
enter image description here

2.Next we must add some resource (e.g some icons) to the project. Do this as usual. Go to the projects setting. Select tab Resources and Add Existing File... to the project. We can see that icon is added to the project and was copied to the local folder;
enter image description here

3.Next step consists of adding this icons to the other project. But one important think! You must add this icon as link. In this case we avoid the resource duplication. OK. Create new Project is same solution and name it for example Main. Create some folder in your other project. For example we can name it as Resource. (Logical name for our purpose). Then right click at this folder. Select Add Existing Item... and choose our image from shared project. Do not forget to add this file as link. Well, you see that just added file can a little differ icon;
enter image description here

Added image must looks like this
enter image description here

4.Now we must set Build Action for this file to None. For this select the file and go to the Properties Window. There choose None for Build Action. We need to do this to avoid the embedding this icon to the Assembly;

enter image description here

5.Well, we must to perform last step to complete task. Open Project Settings for project where we just adds the icon. Choose the Resource tab and drag linked image to the resources.
enter image description here

These five simple steps you must perform to share some icons between projects. But you can ask "What is the benefits of this?" There are:

  • We store resources in one place and it is easy to replace some icon with new one.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download