有没有办法使强类型资源文件公开(而不是内部)?

发布于 2024-07-06 09:46:14 字数 516 浏览 7 评论 0原文

这是我想做的:

我想创建一个包含我的资源文件(即 UI 标签等)的库项目。 然后我想在我的用户界面和测试中使用资源库。 (即,我从多个项目引用的资源基本上都有一个公共位置。)

不幸的是,由于 StronglyTypedResourceBuilder (生成资源代码的 .Net 类)默认将资源文件设为内部资源文件,因此我无法引用我的强类型资源从另一个项目(即我的 UI 或测试)在库中键入资源,而无需跳过障碍(即类似于所描述的内容 此处,或编写公共包装类/函数)。

不幸的是,这两个解决方案都消除了我保持引用强类型的能力。

有没有人找到一种直接的方法来创建可以从多个项目引用的强类型.Net 资源?

我宁愿避免使用构建事件来完成此任务(即,执行诸如将“内部”的所有实例替换为“公共”之类的操作,但这基本上是我的后备计划,如果我找不到一个答案..

Here's what I'd like to do:

I want to create a library project that contains my Resource files (ie, UI Labels and whatnot). I'd like to then use the resource library both in my UI and in my Tests. (Ie, basically have a common place for my resources that I reference from multiple projects.)

Unfortunately, because the StronglyTypedResourceBuilder (the .Net class which generates the code for Resources) makes resource files internal by default, I can't reference my strongly typed resources in the library from another project (ie, my UI or tests), without jumping through hoops (ie, something similar to what is described here, or writing a public wrapper class/function).

Unfortunately, both those solutions remove my ability to keep the references strongly-typed.

Has anyone found a straight-forward way to create strongly typed .Net resources that can be referenced from multiple projects?

I'd prefer to avoid having to use a build event in order to accomplish this (ie, to do something like replace all instances of 'internal' with 'public', but that's basically my fall-back plan if I can't find an answer..

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

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

发布评论

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

评论(3

如梦亦如幻 2024-07-13 09:46:14

不确定您使用的是哪个版本的 Visual Studio,因此我将为任一版本提供步骤:

VS 2008 - 当您在设计视图中打开 resx 文件时,顶部的“添加资源”和“删除资源”旁边有一个选项,称为“访问修饰符” ,它是一个下拉菜单,您可以在其中将生成的代码从内部更改为公共。

VS 2005 - 您无法像 VS 2008 那样生成代码。由于这个令人头疼的问题,所以添加了一个功能。 不过还有解决办法。 您可以使用像这样的第三方生成器 工具 或您可以在 AssemblyInfo 中使用 InternalsVisibleTo 属性.cs 添加将有权访问资源库的内部类的项目。

Not sure which version of Visual Studio you are using, so I will put steps for either one:

VS 2008 - When you open the resx file in design view, there is an option at the top beside Add Resource and Remove Resource, called Access Modifier, it is a drop down where you can change the generated code from internal to public.

VS 2005 - You don't have the option to generate the code like in VS 2008. It was a feature that was added, because of this headache. There are work around's though. You could use a third party generator like this tool or you could use the InternalsVisibleTo attribute in your AssemblyInfo.cs to add the projects that will have access to the internal classes of your resource library.

别把无礼当个性 2024-07-13 09:46:14

Visual Studio 2008 允许您选择生成的资源类是内部的还是公共的。 还有 ResXFileCodeGeneratorEx,它应该可以为 Visual Studio 2005 执行此操作。

Visual Studio 2008 allows you to select whether the generated resource class should be internal or public. There is also the ResXFileCodeGeneratorEx, which should do that for Visual Studio 2005.

¢好甜 2024-07-13 09:46:14

从数据集设计器和可见的属性窗口中,有一个“Modifier”属性。 对于您的数据集,可能会说内部。

我不知道是否有一个设置可以将所有新数据集默认公开。

From the dataset designer and with the properties window visible, there is a "Modifier" property. For your datasets, it is likely saying internal.

I don't know if there is a setting to default all new datasets to public.

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