Visual Studio 解决方案——任何创建“特殊”项目的方法。文件夹?
基本上,我希望我的一个文件夹作为一种“特殊文件夹”出现在其他文件夹之上,类似于 Properties 如何拥有自己的特殊位置,即使它是一个文件夹,与 App_Data 等相同。
这可能吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
默认情况下,Visual Studio 不支持添加特殊项目文件夹。 Properties 文件夹是硬编码的,以使其行为方式如此。
然而,通过代码一切皆有可能。您可以构建一个扩展来执行此操作,但这并不简单。您可能需要搞乱
IVsHierarchy
甚至实现 项目子类型。By default, Visual Studio doesn't support adding special project folders. The Properties folder is hard-coded to behave the way that it does.
However, anything is possible with code. You could build an extension to do this, but it wouldn't be simple. You'd probably need to mess around with the
IVsHierarchy
or even implement a project subtype.是:
生成/修改您的
*.sln
/*.vcproj
对于 (1) IDE 中解决方案的“手册”:
Solution Explorer
、右键单击
解决方案节点
==>添加
==>新建解决方案文件夹
。虽然文件夹通常按字母顺序排序(我会插入一个前导下划线以强制将您的特殊文件夹放在顶部),但在我的 MSVS2008 上手动插入的解决方案文件夹将新文件夹保留在“顶部”,即使它应该在按字母顺序排序。但是,
Project
下的文件夹(称为“Filters
”)始终按字母顺序排序,并通过右键单击以类似方式添加,然后您可以修改其“过滤器” properties”,其中包含您想要的文件名 glob(例如,为“*.MY_EXTENSION1;*.MY_EXTENSION2
”添加过滤器 glob)。我们选择 (2),并生成自己的
*.sln
和*.vcproj
,添加我们自己的文件夹/过滤器。我在网上没有看到任何实用程序可以帮助解决这个问题(所以我们必须编写自己的实用程序)。这些格式不太难进行逆向工程,但它很大程度上是未记录的 XML,因此您必须进行试验。只有几篇很好的网络文章解释了文件中的内容,例如:http://tim.oreilly.com/pub/a/dotnet/excerpt/vshacks_chap1/index.html?page=4
关于“明亮side”,文件只是 XML,因此在开发脚本时,我们只需通过 IDE 进行更改、保存并比较“差异”以了解我们想要的更改。这些更改是我们修改文件时脚本插入的内容。因此,如果您手动修改文件,您也可以类似地“
diff
”文件以查看更改的内容,并制作您自己的脚本。 (恕我直言,这是最快、最简单的途径,因为通常不存在操作这些文件的工具。)诸如 CMake 和 QMake 之类的工具会生成 *.vcproj< /code>/
*.sln
,但不要像您所说的那样真正进行文件夹自定义操作。然而,我们也会查看它们的输出,因为,这些文件中“有不止一种做事的方法”,并且这些文件似乎有许多未记录的功能,用于执行这些工具不知何故“发现”的不同聪明的事情(所以你可以尝试复制他们生成的输出)。我们发现 .NET API 处理这些文件的工作量太大,而且并不是真正为这种类型的操作而设计的,但是 YMMV。
Yes:
generate/modify your
*.sln
/*.vcproj
For (1) "manual" on solutions in the IDE:
Solution Explorer
,right-click
onSolution node
==>Add
==>New Solution Folder
.While typically the folders are sorted alphabetically (I'd insert a leading underscore to force your special folder to the top), solution folders inserted manually on my MSVS2008 leave the new folder "at the top", even though it should have bumped down when alphabetically sorted. However, folders under a
Project
(which are called "Filters
") are always sorted alphabetically, and added similarly from the right-click, and then you can modify their "filter properties" with file name globs for what you want in there (e.g., add a filter glob for "*.MY_EXTENSION1;*.MY_EXTENSION2
").We chose (2), and we generate our own
*.sln
and*.vcproj
, adding our own folders/filters. I've not seen any utilities on the web to help with that (so we had to write our own). The formats are not too hard to reverse engineer, but it's largely undocumented XML, so you have to experiment. There are only a couple good web articles explaining what's in the file, like this one:http://tim.oreilly.com/pub/a/dotnet/excerpt/vshacks_chap1/index.html?page=4
On the "bright side", the files are only XML, so in developing our scripts we merely made changes through the IDE, saved, and compared the "diffs" for what change we want. Those changes are what our scripts insert when we modify our files. So, if you modify the file manually, you can similarly just "
diff
" the file to see what changed, and make your own script. (IMHO, this is the fastest and easiest route, since tools generally do not exist to manipulate these files.)Tools like
CMake
andQMake
generate*.vcproj
/*.sln
, but don't really do the folder customization thing like you're talking. However, we look at their output too, because, "there's more than one way to do things" in these files, and the files seem to have many undocumented features for doing different clever things that somehow these tools have "discovered" (so you can try to copy their generated output).We found the .NET APIs to work with these files as too much work, and not really designed for that type of manipulation, but YMMV.
VS 2012有一个我刚刚发现的功能,它为我解决了这个问题。对于VS来说,这可能并不新鲜。
在项目下创建一个以“_”开头的文件夹(以便首先对其进行排序)。
在文件夹的属性上将“Namespace Provider”设置为 false。
VS(或 ReSharper?)代码分析不会抱怨“命名空间与文件位置不匹配”,这对我来说是恼怒的根源,否则会让我无法走这条路。
VS 2012 has a feature that I just found, and it solved this problem for me. It may not be new to VS.
Create a folder under the project with a leading "_" (to get it sorted first).
On the folder's properties set "Namespace Provider" to false.
VS (or ReSharper?) code analysis then does not complain that "the namespace does not match file location", which was the source of irritation for me that would otherwise have kept me from going this route.
虽然添加
自定义文件夹
没有简单的方法,但有一种简单的方法可以“窃取”Properties
自定义文件夹。向项目添加常规文件夹。例如
MyCustomerFolder
。打开项目文件 xml.查找行
替换为
重新加载项目。
现在您已经有了一个自定义文件夹,它将始终位于顶部。
Although there is no easy way to add
Custom Folder
, there is an easy way to "steal"Properties
custom folder.Add a regular folder to the project. For example
MyCustomerFolder
.Open proj file xml. Find line
replace with
Reload the project.
Now you've got a custom folder, that will always stick to the top.