winformsvisual-studio-designer

Issue with shared WinForms resources across projects in Visual Studio


I've moved all image resources in a large multi-project solution to a new project specifically created for shared resources.

Adding a new reference to other projects where the shared images are used is working as expected. The image in the selected button below continues to appear in designer but with issues.

In VS Designer, I'm unable to select shared resources in the Image Editor, having instead to manually edit the designer code.

More specifically, in the Image Editor dialog (accessed from the 'Image' property of an existing control) I select 'Select from File/Resource..." to pop up the Select Resource dialog (shown). There, where I used to access all local project resources (Resources.resx), I would like now to add access to the new shared resources project. Ideally, I would add a second item to the dropdown shown which switches to the resx for the shared resources project.

How can this be done? Is there a better way?

alt text


Solution

  • I was able to share a resx file between project and using it in the designer in VS 2008 SP1 (I don't know other versions). Differently from other approaches, here resources are statically and dynamically shared, so at runtime there's really one copy of the shared resources. No storage or memory waste and it's easy to maintain with tons of projects.

    Follow the guide and tell me if it works for you:

    The project in the Solution Explorer should look like this:

    enter image description here

    Now in any project you need the resx file to be shared do this:

    Obviously, the "Include" attribute should be the correct relative path to GlobalResources.resx.

    In my project, the following lines are generated and added to the project automatically when I do this:

    <Compile Include="..\Resources\GlobalResources.Designer.cs">
      <Link>GlobalResources.Designer.cs</Link>
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>GlobalResources.resx</DependentUpon>
    </Compile>
    

    If they aren't added, add them manually.

    Now the project should look like this in the Solution Explorer (likend files should be marked differently):

    enter image description here

    Last two steps:

    enter image description here

    enter image description here

    And you are done: at this point you should really be able to use the resources you added in the shared resx in the designer selecting "GlobalResources.resx" in the "Project Resource file" dialog of your question. And as told it's really shared even at runtime! In the Properties panel you should see the full Namespace and class of the external project. If you remove the dependency on the "Resource" project it doesn't even compile. If it doesn't work for you, insist until it works and in case tell me where the guide is wrong. It have to work! Let me know.