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

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

问题描述

如何防止 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"解决方案文件夹名称附加到命名空间.

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

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