如何不在生成的名称空间中包括Visual Studio Project文件夹名称 [英] How to NOT include Visual Studio Project folder names in generated namespaces

查看:69
本文介绍了如何不在生成的名称空间中包括Visual Studio Project文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止VS项目中解决方案文件夹"的名称附加到为添加到解决方案文件夹的新项目生成的命名空间中?

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解决方案中的C#项目 在C#项目属性中设置的默认命名空间:"BigClient.Domain"

Example: C# project in a VS solution Default Namespace set in C# project properties: "BigClient.Domain"

如果您在此项目中创建一个名为"MySpecialStuff"的解决方案文件夹,然后向"MySpecialStuff"解决方案文件夹中添加新类,则VS将使用"BigClient.Domain.MySpecialStuff"命名空间创建新的.cs文件.找到一种方法来允许新添加的类的名称空间仅保留"BigClient.Domain"的项目级"名称空间,而不是VS将"MySpecialStuff" solution-folder-name附加到名称空间.

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.

我似乎回想起某人读过一篇博客文章的可能性(通过VS中的选项/设置或注册表设置),但我无法回忆起现在想要的位置或方式:)

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版本的答案不同,那么我的平台是VS 2008.

My platform is VS 2008 if answer = different for different VS versions.

推荐答案

制作新的类模板或更改Visual Studio的类模板.有关此操作,请参阅MSDN文档.在模板文件中,您很快就会看到插入安全"名称空间名称的行.

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 Project文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆