Visual Studio 2010:将自动生成的资源折叠在其他文件后面?

发布于 2024-11-11 23:08:38 字数 1299 浏览 4 评论 0原文

我有以下文件: Foo.cs ,其中有一个 Foo 类。我似乎找不到正确的方法来将我的资源文件(resx)组织在各自的文件后面。

  1. 如果我创建 Foo.resx,资源文件就会整齐地折叠在 Foo.cs 类后面。然而,这会导致问题,因为生成代码的标准自定义工具尝试创建另一个 Foo 类(查看 Foo.Designer.cs:internal class Foo { ... } )。如果我的 Foo.cs 文件尚未包含 Foo 类,则效果很好(没有命名冲突)。

  2. 为了解决命名冲突,我尝试给它一个自定义命名空间 MyProj.Resources 并使用别名来标识它: using R = MyProj.Resources.Foo; 这仍然会导致问题,因为自动-generator 在正确创建 ResourceManager 时出现问题。

  3. 如果我将其命名为类似于 FooResx.resx 的名称,它不会自动折叠到 Foo.cs 文件后面。相反,它位于其正下方的解决方案资源管理器中。进入 MSBuild (.csproj) 文件并添加 标记,然后 Visual Studio 整齐地隐藏我的 FooResx.resx 文件。但是,我实际上无法使用该文件中的任何资源,因为自动生成的代码在正确创建 ResourceManager 时存在问题。

基本上,有没有办法让资源文件 (resx) 折叠在 cs 文件后面,并且仍然使用标准自定义工具 (ResXFileCodeGenerator) 正常工作?


我确实意识到我始终可以将所有资源放入属性文件夹中的文件中:resources.resx。不过,我正在努力将它们组织得更好。


更新:

我决定手动编辑自动生成的代码并使其部分化。这允许代码编译,但我仍然遇到同样的问题(问题#2)。看起来,如果一个资源文件(手动或自动)折叠在另一个代码文件后面,那么 ResourceManager 就很难找到 *.resource 文件。这可能是我必须向 Microsoft Connect 提出有关 ResXFileCodeGenerator 工具的问题。当折叠在其他文件后面时,它需要能够找到正确的 *.resource 文件。

I have the following file: Foo.cs with a Foo class inside of it. I can't seem to find the right way to keep my resource files (resx) organized behind their respective files.

  1. If I create a Foo.resx the resource file gets folded away nice and tidy behind the Foo.cs class. This, however, causes issues because the standard custom-tool that generates the code attempts to create another Foo class (Look at the Foo.Designer.cs: internal class Foo { ... }). If my Foo.cs file does not already contain a Foo class, this works fine (no naming collision).

  2. To fix the naming collision I attempted to give it a custom namespace MyProj.Resources and use an alias to identify it: using R = MyProj.Resources.Foo; This still causes issues because the auto-generator has an issue creating a ResourceManager properly.

  3. If I, instead, name it something along the lines of FooResx.resx it does not automatically get folded behind the Foo.cs file. Instead, it resides in the solution explorer right below it. Going into the MSBuild (.csproj) file and adding a <DependentUpon> tag, then Visual Studio neatly tucks away my FooResx.resx file. However, I can't actually use any of the resources from that file because the auto-generated code has an issue creating a ResourceManager properly.

Basically, is there any way to have the Resource files (resx) fold behind a cs file and still work properly using the standard Custom Tool (ResXFileCodeGenerator)?


I do realize that I can always place all my resources into a file within the properties folder: resources.resx. I'm trying to organize them better than that though.


Update:

I decided to manually edit the auto-generated code and make it partial. This allowed the code to compile, but I still ran into the same issue (Issue #2). It seems that if a resource file is folded behind (manually or automatically) another code file then the ResourceManager has trouble finding the *.resource file. This might be an issue I'll have to raise with Microsoft Connect about the ResXFileCodeGenerator tool. It needs to be able to locate the proper *.resource file when folded behind other files.

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

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

发布评论

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

评论(1

橘虞初梦 2024-11-18 23:08:38

解决方案可能是使您的类和生成的代码部分类 - 如果您查看 .Designer.cs(例如来自 System.Windows.Forms.Form),您会发现它声明类似于部分类Foo

Foo.cs

public partial class Foo
{
}

Foo.Designer.cs

partial class Foo
{
}

编辑

原来是StronglyTypedResourceBuilderPublicResXFileCodeGenerator 坚持使用 internalpublic 访问修饰符生成类(可以在 .resx 中设置)。

在 .resx 的属性中将 ResXFileCodeGenerator 设置为 CustomTool 仍然无法提供在 生成的 .Desinger.cs 中看到的行为表单

The solution could be to make your classes and your generated code partial classes - if you look at a .Designer.cs (from a System.Windows.Forms.Form for example) you will discover that it declares something like partial class Foo.

Foo.cs

public partial class Foo
{
}

Foo.Designer.cs

partial class Foo
{
}

Edit

It turns out that StronglyTypedResourceBuilder or PublicResXFileCodeGenerator insists on generating classes with either internal or public access modifier (it can be set in the .resx).

Setting ResXFileCodeGenerator as the CustomTool in the properties of your .resx still doesn't give you the behaviour you'd see in a generated .Desinger.cs of a Form.

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