包含 2 个项目的解决方案 - 共享 Properties.Resources

发布于 2024-07-09 10:03:10 字数 562 浏览 5 评论 0原文

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

第一个项目包含 Form1,它显示一个标签,其中文本设置为来自 Properties.Resources 的字符串,如下所示:

label1.Text = Properties.Resources.MY_TEXT;

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

不幸的是,第二个项目无法构建,并显示以下错误消息:“当前上下文中不存在名称“属性””。

有什么办法可以解决这个问题吗? 我尝试将第一个项目中的“Resources.resx”文件“添加为链接”,但没有帮助。

编辑:我发现如果我将 Project1 添加为 Project2 中的参考,则一切正常。 我还必须将 Project1 资源中的访问修饰符从内部更改为公共。 这是正确的方法吗?

谢谢你, 彼得

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖树树初阳… 2024-07-16 10:03:10

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

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

您还询问了有关组合程序集的问题。 查看 ILMerge 工具

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.

浪推晚风 2024-07-16 10:03:10

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文