简体   繁体   English

使命名空间忽略某些文件夹C#visual studio

[英]make namespace ignore certain folder C# visual studio

So I'm currently in the process of creating some Item Templates in visual studio for some commonly used classes I have to make. 因此,我目前正在Visual Studio中为一些我必须制作的常用类创建一些项模板。 During this task I've run in to another problem. 在执行此任务期间,我遇到了另一个问题。

I'm using folders prefixed with _ as sort of grouping folders that don't affect the namespace. 我正在使用以_开头的文件夹作为不影响名称空间的分组文件夹。 However, when I create a new item in one of these folders, the _Folder is automatically appended to the workspace like so: namespace Core.Parser._Filters 但是,当我在这些文件夹之一中创建新项目时,_Folder会自动添加到工作区中,如下所示: namespace Core.Parser._Filters

Usually I would just go by hand and remove the prefixed folders from the namespace, but since I'm trying to automate this process that's no longer an option. 通常,我只需要手工删除命名空间中的前缀文件夹,但是由于我试图使此过程自动化,因此不再是一种选择。

So I've thought of 2 ways i could solve this, but I'm not sure how they would work in practice or if they're even possible. 因此,我想到了两种方法可以解决此问题,但是我不确定它们如何在实践中发挥作用,甚至不确定是否可行。

1) Would it somehow be possible to tell VS to exclude a folder from namespace construction? 1)可以以某种方式告诉VS从名称空间构造中排除文件夹吗? Similarly to how you can set the Build Action on .cs files to None so VS skips over them during compile. 与将.cs文件的“生成操作”设置为“无”类似,因此VS在编译过程中会跳过它们。

2) Would it be possible to add a modifier to the Item Template which strips out the prefixed folders from $rootnamespace$ ? 2)是否可以在项目模板中添加修饰符,以从$rootnamespace$删除带前缀的文件夹? Something like ($rootnamespace$).Replace("._Filters", ""); ($rootnamespace$).Replace("._Filters", "");

This will prevent Visual Studio from using the folder name as part of the namespace (if ReSharper is installed): 这将阻止Visual Studio将文件夹名称用作名称空间的一部分(如果已安装ReSharper):

Right-click on folder -> Properties -> NamespaceProvider = false 右键单击文件夹->属性-> NamespaceProvider = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM