解决方案有2个项目 - 共享Properties.Resources

时间:2023-01-16 16:43:14

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

在Visual C#2008中,我有一个包含两个项目的解决方案。

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

第一个项目包含Form1,它显示一个Label,Text设置为Properties.Resources中的字符串,如下所示:

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.

在第二个项目中,我从第一个项目“添加链接”这个Form1。我想显示这个表单,所以它显示与从第一个项目调用时相同。它应该显示一个标签,其中包含在第一个项目中定义的文本Properties.Resources.MY_TEXT。

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.

有什么方法可以解决这个问题吗?我试图从第一个项目“添加链接”“Resources.resx”文件,但它没有帮助。

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?

编辑:我发现,如果我在Project2中添加Project1作为参考,一切正常。我还必须将Project1资源中的Access Modifier从Internal更改为Public。这是正确的方法吗?

Thank you, Petr

谢谢你,彼得

2 个解决方案

#1


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.

是的,这是正确的方法(从另一个项目引用一个项目)。您可能希望应用的模式是让一个项目包含所有参考/查找/设置。然后,您不需要计算UI项目之间的依赖关系。

Your approach of making the resources public is the correct.

您公开资源的方法是正确的。

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

您还询问了组合装配。看看ILMerge工具。

#2


0  

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

您应该添加“使用MyOtherProjectNamespace”,以便您可以访问其属性

#1


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.

是的,这是正确的方法(从另一个项目引用一个项目)。您可能希望应用的模式是让一个项目包含所有参考/查找/设置。然后,您不需要计算UI项目之间的依赖关系。

Your approach of making the resources public is the correct.

您公开资源的方法是正确的。

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

您还询问了组合装配。看看ILMerge工具。

#2


0  

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

您应该添加“使用MyOtherProjectNamespace”,以便您可以访问其属性