views:

603

answers:

3

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

A: 

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

+1  A: 

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
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
@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
A: 

Thanks for your comments. I have one more question: in the Debug directory of Project2, there is also Project1.exe automatically created. If I try to remove it and run Project2.exe, it doesn't run (Project2 links to Project1, so this behavior is probably right). Can I somehow link everything to one exe file, so I don't need to send both Project1.exe and Project2.exe?

What you want there is the ILMerge tool. See my answer.
Robert Wagner