Using images from another project in VS 2010

This post is a little self-serving, as I might be the only one who needs to know this in the future, but I’m sure I’ll forget all about this some day when I google this problem and find the answer in my own post.

Today I needed to use an image that was in one VS2010 project in a control of another project in the same solution. While you can certainly copy and paste the image into both resource files, I found a way that I can share the same file.

Step 1: Right-click the project you want the image in and choose ‘Unload Project’ from the context menu.
Step 2: Right-click the project again and choose ‘Edit [project name].csproj’.
Step 3: Find a <ItemGroup> section and insert the following code into it:

,EmbeddedResource Include="..\[project name]\Properties\Resources.resx">
    <Link>[assembly name].Properties.Resources.resx</Link>
    <Generator>ResXFileCodeGenerator</Generator>
    <LastGenOutput>[assembly name].Properties.Resources.Designer.cs</LastGenOutput>
    <CustomToolNamespace>[assembly name].Properties</CustomToolNamespace>
</EmbeddedResource>

Replace “[project name]” with the actual name of the project that contains the resource file of the image you want to use.
Replace “[assembly name]” with the actual name of the assembly for the project.

Step 4: Right-click the project and choose ‘Reload Project’. If prompted, allow VS to close the .csproj file.
Step 5: When you bring up the Image picker dialog for the control, you’ll now have the new resource file to choose from in the dropdown menu:

VS2010_Sharing_Project_Images

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s