Visual Studio 2010: Folding auto-generated resources behind other files?
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.
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 aFoo
class, this works fine (no naming collision).To fix the naming collision I attempted to give it a custom namespace 开发者_JAVA技巧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 aResourceManager
properly.If I, instead, name it something along the lines of
FooResx.resx
it does not automatically get folded behind theFoo.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 aResourceManager
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.
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
.
精彩评论