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:
- Create a class project Resources;
- Create a resource file (go to Properties -> Resources of the project);
- Move the resource file (default Resources.resx) to the root of the project;
- Rename the resources file Resources.resx -> GlobalResources.resx;
- Modify the resources file modifier to Public (double click on the resources file, "Access Modifier" -> "Public");
- Copy any resource file to the root directory of the project;
- Add any resource to the resource file using "Add Existing File" and selecting resources on the root directory of the project.
The project in the Solution Explorer should look like this:
Now in any project you need the resx file to be shared do this:
Add the "Resource" project as a dipendency;
Edit manually the project file (*.csproj) and add the following lines in the resources file ItemGroup (create a local resource file if you want to see it):
<ItemGroup>
...
<EmbeddedResource Include="..ResourcesGlobalResources.resx">
<Link>GlobalResources.resx</Link>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>GlobalResources.Designer.cs</LastGenOutput>
<CustomToolNamespace>Resources</CustomToolNamespace>
</EmbeddedResource>
...
</ItemGroup>
Obviously, the "Include" attribute should be the correct relative path to GlobalResources.resx.
- Use the resources in the designer as you was asking.
In my project, the following lines are generated and added to the project automatically when I do this:
<Compile Include="..ResourcesGlobalResources.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):
Last two steps:
- Click on the linked "GlobalResources.resx" and on the Properties set "None" as the "BuildAction". "Custom Tool Namespace" should already be set to "Resources";
- Click on the linked "GlobalResources.Designer.resx" and on the Properties set "None" as the "BuildAction".
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…