Visual Studio Resource Generation - Custom Tool Namespace

情到浓时终转凉″ 提交于 2019-12-30 03:09:49

问题


I have a C# class library that contains several resources files organized in folders. Since I want the generated classes to be all in the same namespace I'm setting the CustomToolNamespace property of each resource file.

However I discovered through Reflector that although the classes are all being generated in the same namespace the path to the embedded resources contains the directory name in which the resource file is placed.

For example in a project where FolderCustomNamespaceRes.resx is placed inside a directory named Folder.

removed dead ImageShack link

And where CustomToolNamespace for FolderCustomNamespaceRes.resx is set to PublicResourcesTest, Reflector shows that the path to the embedded resource assembly is PublicResourcesTest.Folder.FolderCustomNamespaceRes.resources

removed dead ImageShack link

Is this a bug or am I missing something?


回答1:


After some search I found out that the manifest name of the embedded resource can be controlled by adding metadata in the .cspproj file.

Before you would have something like:

<EmbeddedResource Include="Folder\FolderCustomNamespaceRes.resx">
   <Generator>PublicResXFileCodeGenerator</Generator>
   <LastGenOutput>FolderCustomNamespaceRes.Designer.cs</LastGenOutput>
   <CustomToolNamespace>PublicResourcesTest</CustomToolNamespace>
</EmbeddedResource>

And to control the manifest name you would have to add:

<EmbeddedResource Include="Folder\FolderCustomNamespaceRes.resx">
   ....
   <LogicalName>$(RootNamespace).FolderCustomNamespaceRes.resources</LogicalName>
</EmbeddedResource>



回答2:


This is done automatically by the IDE so it's not a bug, but unfortunately the only way it appears you can suppress this behaviour is by using ReSharper as outlined here.



来源:https://stackoverflow.com/questions/2043399/visual-studio-resource-generation-custom-tool-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!