visual-studio 如何不在生成的命名空间中包含 Visual Studio 项目文件夹名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/503908/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to NOT include Visual Studio Project folder names in generated namespaces
提问by sbohlen
How do I prevent the name of the Solution Folder in a VS project from being appended to the namespace generated for new items added to the solution folder?
如何防止将 VS 项目中解决方案文件夹的名称附加到为添加到解决方案文件夹的新项目生成的命名空间?
Example: C# project in a VS solution Default Namespace set in C# project properties: "BigClient.Domain"
示例:VS 解决方案中的 C# 项目在 C# 项目属性中设置的默认命名空间:“BigClient.Domain”
If you create a solution folder in this project called "MySpecialStuff" and then add a new class to the 'MySpecialStuff" solution folder, VS creates the new .cs file with a "BigClient.Domain.MySpecialStuff" namespace. I want to find a way to allow the namespace of the newly-added class to retain just the 'project-level' namespace of "BigClient.Domain" instead of VS appending the "MySpecialStuff" solution-folder-name to the namespace.
如果您在此项目中创建一个名为“MySpecialStuff”的解决方案文件夹,然后将一个新类添加到“MySpecialStuff”解决方案文件夹中,VS 将使用“BigClient.Domain.MySpecialStuff”命名空间创建新的 .cs 文件。我想找到一个允许新添加的类的命名空间仅保留“BigClient.Domain”的“项目级”命名空间而不是 VS 将“MySpecialStuff”解决方案文件夹名称附加到命名空间的方法。
I seem to recall reading a blog post by someone that this was possible (either via options/settings in VS or a registry setting) but I cannot recall where or how now that I want it :)
我似乎记得读过某人的博客文章,这是可能的(通过 VS 中的选项/设置或注册表设置),但我不记得现在我想要它的位置或方式:)
My platform is VS 2008 if answer = different for different VS versions.
如果答案 = 不同 VS 版本不同,我的平台是 VS 2008。
采纳答案by bdukes
Make a new class template or change Visual Studio's class template. See the MSDN documentation for how to this. In the template file, you quickly see the line that inserts the 'safe' namespace name.
创建一个新的类模板或更改 Visual Studio 的类模板。有关如何执行此操作,请参阅 MSDN 文档。在模板文件中,您很快就会看到插入“安全”命名空间名称的行。
回答by bdukes
If you have ReSharper installed, on the settings for the directory (F4), set Namespace Provider to false.
如果您安装了 ReSharper,则在目录设置 (F4) 上,将 Namespace Provider 设置为 false。

