2

In Visual C# 2008, I have a solution with two projects.

First project contains Form1 that displays one Label with Text set to a string from Properties.Resources, like this:

label1.Text = Properties.Resources.MY_TEXT;

In the second project, I "Add as link" this Form1 from the first project. I want to show this form, so it displays the same as when called from the first project. It should show a label with text Properties.Resources.MY_TEXT defined in the first project.

Unfornately, the second project doesn't build with the following error message: "The name 'Properties' does not exist in the current context".

Is there any way how to resolve this? I have tried to "Add as link" the "Resources.resx" file from the first project, but it doesn't help.

EDIT: I found that if I add Project1 as a Reference in Project2, everything works. I also had to change Access Modifier in the Project1 resources from Internal to Public. Is this the right approach?

Thank you, Petr

user20353
  • 1,293
  • 4
  • 15
  • 28
  • FYI, some WinForms components, mainly the MenuStrip / ToolStrip etc. gang, still won't allow you to share their resources (e.g. button images) using this public visibility trick. Unless you're willing to hand-edit *.Designer.cs each time you change the form, that is---a royal PITA. – Alan Nov 15 '08 at 21:03
  • I think we are only talking about resx files here. – Robert Wagner Nov 17 '08 at 22:04
  • Robert, your solution is correct. It's just that *Strip components do not support design time codegen w/public resources (e.g. "global::MySharedProjectFile.Properties.Resources.WHATEVER"), so if Petr wants to use toolbar images from another project, not just label text, he's in for a nasty surprise. – Alan Nov 24 '08 at 07:00

2 Answers2

2

Yes that is the right approach (referencing one project from another). A pattern you may like to apply is to have one project that has all your reference/lookup/settings in it. Then you don't need to work out dependencies between your UI projects.

Your approach of making the resources public is the correct.

You also asked about combining assemblies. Have a look at the ILMerge tool.

Robert Wagner
  • 17,515
  • 9
  • 56
  • 72
  • Do be careful to ensure that this is what you want to do, however. At that point you're tightly coupling your binaries. This may be perfectly acceptable in your case, which is great, but there are many situations where it won't be. – Greg D Nov 17 '08 at 19:01
  • @Greg Agreed, hence the suggestion of putting all that stuff into a common, non-UI library. I think dynamic loading is a bit advanced for this situation. – Robert Wagner Nov 17 '08 at 22:06
0

You should add "using MyOtherProjectNamespace" so that you can access its properties

user19871
  • 171
  • 6