visual-studio Visual Studio 解决方案文件夹作为真正的文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/267200/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:52:34  来源:igfitidea点击:

Visual Studio Solutions Folder as real Folders

visual-studio

提问by Michael Stum

I have a Visual Studio Solution. Currently, it is an empty solution (=no projects) and I have added a few solution folders.

我有一个 Visual Studio 解决方案。目前,它是一个空的解决方案(= 没有项目),我添加了一些解决方案文件夹。

Solution Folders only seem to be "virtual folders", because they are not really created in the Filesystem and files inside solution folders are just sitting in the same folder as the .sln file.

解决方案文件夹似乎只是“虚拟文件夹”,因为它们并不是真正在文件系统中创建的,解决方案文件夹中的文件只是与 .sln 文件位于同一文件夹中。

Is there a setting that i've overlooked that tells Visual Studio to treat Solution Folders as "real" folders, that is to create them in the file system and move files into it when I move them inside the solution into one of those folders?

是否有我忽略的设置告诉 Visual Studio 将解决方案文件夹视为“真实”文件夹,即在文件系统中创建它们并将文件移入其中,当我将它们移入解决方案中的一个文件夹中时?

Edit:Thanks. Going to make a suggestion for VS2010 then :)

编辑:谢谢。打算对 VS2010 提出建议:)

采纳答案by svlists

No special setting. I don't think it's supported.

没有特别的设定。我认为它不受支持。

You can create real folders in a "project" within the solution, but not in the solution itself.

您可以在解决方案内的“项目”中创建真正的文件夹,但不能在解决方案本身中创建。

回答by Michael

There is a workaround, that actually behaves as expected.

一种解决方法,它实际上按预期运行

  1. Add a Newor Existing Web Siteto the Solution. (I usually create a new one.)
  2. Just make sure it's created inside your solution folder. (I sometimes even create a "link" to an external folder, e.g. 'Docs' or 'Marketing' on a network share. In that case it's ignored by Git of course.)
  3. Make sure to go to the "Project" settings or Configuration Manager to exclude this "Web Site" from Build and Deploy!
  1. 向解决方案添加新的现有的网站。(我通常创建一个新的。)
  2. 只需确保它是在您的解决方案文件夹中创建的。(有时我什至会在网络共享上创建一个指向外部文件夹的“链接”,例如“Docs”或“Marketing”。在这种情况下,Git 当然会忽略它。)
  3. 确保转到“项目”设置或配置管理器以从构建和部署中排除此“网站”

Done. Now Solution Explorer will reflect any change in the file system and vice versa(including subfolders).

完毕。现在解决方案资源管理器将反映文件系统中的任何更改,反之亦然(包括子文件夹)。

I (miss)use it for specs, docs, PM and some DevOps scripts that are shared within the team. It's easy to choose, what to include in source control or not, and (if set up correctly) it doesn't conflict with build.

我(错过)将它用于规范、文档、PM 和一些团队内部共享的 DevOps 脚本。它很容易选择,在源代码管理中包含与否,并且(如果设置正确)它不会与构建冲突。

I know the feature is not intended for that use case, but except for the maybe misleading "Project" icon I didn't find any shortages to that hack yet. And there still are use cases where the classical (virtual) Solution Folders that VS provides, fit in the picture. What do you think?

我知道该功能不适用于该用例,但除了可能具有误导性的“项目”图标外,我还没有发现该 hack 有任何不足之处。并且仍然有一些用例,其中 VS 提供的经典(虚拟)解决方案文件夹适合图片。你怎么认为?

回答by OdeToCode

In Visual Studio 2017, click on the "Solutions and Folders" icon in the Solution Explorer window. This button toggles from the virtual "solution" view into a "source view" that matches the layout of folders and files on the file system. When you add a new folder, the folder is physically created in the expected location. solutions and folders.

在 Visual Studio 2017 中,单击“解决方案资源管理器”窗口中的“解决方案和文件夹”图标。此按钮从虚拟“解决方案”视图切换到与文件系统上的文件夹和文件布局相匹配的“源代码视图”。添加新文件夹时,会在预期位置物理创建该文件夹。 解决方案和文件夹.

回答by rsenna

The chosen answer suggests it would be possible to use actual projects instead of solution folders, but does not really explain how. I guess what I'm describing here is possibly the least awkwardway of achieving that... :-P

所选答案表明可以使用实际项目而不是解决方案文件夹,但并未真正解释如何使用。我想我在这里描述的可能是实现这一目标的最不尴尬的方式...... :-P

The problem with regularproject files is that they eventually will be compiled by MSBUILD. And if you want have a project which only contains non-compilable files, that willbe an issue.

常规项目文件的问题在于它们最终将由MSBUILD. 如果你想要一个只包含不可编译文件的项目,那是一个问题。

But some time ago Visual Studio introduced a new project type: Shared Project(.shproj extension). This project type does notget compiled by default, but only when (and only if) it is referenced by another project.

但前段时间 Visual Studio 引入了一种新的项目类型:共享项目(.shproj 扩展名)。默认情况下不会编译此项目类型,但仅当(且仅当)它被另一个项目引用时才编译。

So one part of the trick here is to use shared projects instead of solution folders. It's obviously possible to add a shared project that is neverreferenced by any other project, meaning we can avoid the issue presented above.

所以这里的技巧之一是使用共享项目而不是解决方案文件夹。显然可以添加一个从未被任何其他项目引用的共享项目,这意味着我们可以避免上述问题。

Then, by using <None Include="**/*" />clause in the .shproj file, we can make it automaticallyreflect any new files and/or subfolders.

然后,通过<None Include="**/*" />在 .shproj 文件中使用子句,我们可以使其自动反映任何新文件和/或子文件夹。

So basically do this:

所以基本上这样做:

  • Create a new folder in your solution.
  • Add a new .shproj file at the root of this new folder.
  • Reference the new .shproj in your solution.
  • 在您的解决方案中创建一个新文件夹。
  • 在这个新文件夹的根目录添加一个新的 .shproj 文件。
  • 在您的解决方案中引用新的 .shproj。

For instance, in my case, I've created a DockerDev.shproj, so I can group some docker-related scripts that we run only in our development machines:

例如,就我而言,我创建了一个 DockerDev.shproj,因此我可以将一些仅在我们的开发机器中运行的与 docker 相关的脚本分组:

<?xml version="1.0" encoding="utf-8"?>
<!-- DockerDev/DockerDev.shproj -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="**/*" />
  </ItemGroup>
</Project>

This .shproj file will keep track of anyfile, in anysubfolder of this new DockerDevfolder in my solution.

这.shproj文件将保持跟踪的任何文件,在任何新的子文件夹DockerDev在我的解决方案文件夹。

As far as I could see, this solution works pretty much like what the OP requested: it will work as a non-compilable reference to a folder, and it will automatically reflect any changes made to it.

据我所知,此解决方案的工作方式与 OP 要求的非常相似:它将作为对文件夹的不可编译引用工作,并且会自动反映对其所做的任何更改。

回答by SwampyFox

Sara Ford contributed a Macro to add do this. In Visual Studio 2010, if you open your Macro Explorer, you will see a macro called "GenerateSlnFolderOnDirStructure." This will automate the creation of the Solution Folders and add the files.

Sara Ford 贡献了一个宏来添加执行此操作。在 Visual Studio 2010 中,如果打开宏资源管理器,您将看到一个名为“GenerateSlnFolderOnDirStructure”的宏。这将自动创建解决方案文件夹并添加文件。

回答by ryan

Folder To Solution Folder By Cecilia Wirén - CeciliaSHARP

文件夹到解决方案文件夹 作者 Cecilia Wirén - CeciliaSHARP

Remove the hassle of adding several files to solution folder. Just use the context menu for the solution and just below the option of creating a new solution folder you now find 'Add Folder as Solution Folder'. This will create a solution folder with the same name as you selected and add the items inside of that folder to the solution folder. This will not move the files on disk.

消除将多个文件添加到解决方案文件夹的麻烦。只需使用解决方案的上下文菜单,就在创建新解决方案文件夹的选项下方,您现在可以找到“将文件夹添加为解决方案文件夹”。这将创建一个与您选择的名称相同的解决方案文件夹,并将该文件夹内的项目添加到解决方案文件夹中。这不会移动磁盘上的文件。

回答by Ankit

Note: Yes this is possible you can create a folder on root but its lil bit tricky....

注意:是的,这是可能的,您可以在根目录上创建一个文件夹,但它有点棘手....

By giving some extra efforts you can do it How? Lets follow the step--

通过付出一些额外的努力,你可以做到如何?让我们跟着步骤——

  • 1-Create Folder eg: "newfolder" on root (where your .sln file reside).
  • 2.Copy and paste your projects inside the folder.
  • 3.go to your sln file and find moved projects and append newfolder\ in moved project's address.
  • 4.Save sln file.
  • 5.Open your project and Commit the repository in git or so...
  • 6.Take the repository on fresh location.

    YOU are done...

  • 1-创建文件夹,例如:根目录上的“ newfolder”(您的 .sln 文件所在的位置)。
  • 2.将您的项目复制并粘贴到文件夹中。
  • 3. 转到您的 sln 文件并找到移动的项目并将 newfolder\ 附加到移动的项目地址中。
  • 4.保存sln文件。
  • 5.打开你的项目并在git左右提交存储库...
  • 6.将存储库放在新位置。

    你完了...

if still you are not able to see your folder -----

如果您仍然无法看到您的文件夹 -----

  • 1.Add a solution folder xyz.
  • 2.Open sln file and change that folder name with your folder name.
  • 1.添加解决方案文件夹xyz。
  • 2.打开 sln 文件并使用您的文件夹名称更改该文件夹名称。

Congrats you are done..

恭喜你完成了..

If you face any problem just write me for help..

如果您遇到任何问题,请写信给我寻求帮助。

回答by rc21

Create "Solution folder". This will create logical folder, but not physical one. Right click to the solution folder and open a new project dialog. But before you click OK, you have to change a project location to your desired physical folder and VS will create it and place the project inside.

创建“解决方案文件夹”。这将创建逻辑文件夹,而不是物理文件夹。右键单击解决方案文件夹并打开一个新项目对话框。但是在单击确定之前,您必须将项目位置更改为所需的物理文件夹,VS 将创建它并将项目放置在其中。

回答by Alan

No, it's not supported. As you suspected, solution folders are simply virtual subentries in the .sln file, nothing to do with the file system.

不,它不受支持。正如您所怀疑的,解决方案文件夹只是 .sln 文件中的虚拟子条目,与文件系统无关。

回答by northWind

Visual studio has no support for this. I made an extension that does something similar for VS2013 though. It maps solution folders to physical folders on your hard drive, though the mapping is one way (from hard drive to solution). That means a solution folder's contents will reflect the hard drive folder's contents, and not the other way.

Visual Studio 对此不提供支持。不过,我做了一个扩展,它对 VS2013 做了类似的事情。它将解决方案文件夹映射到硬盘驱动器上的物理文件夹,尽管映射是一种方式(从硬盘驱动器到解决方案)。这意味着解决方案文件夹的内容将反映硬盘驱动器文件夹的内容,而不是相反。

With that out of the way, the extension may still be useful. It has support for mapping solution folders to physical folders, filtering files and directories based on regex, and remembering mappings in your .sln file. Properties are non-intrusive so developers without the extension can still open the sln and not be affected.

这样一来,扩展可能仍然有用。它支持将解决方案文件夹映射到物理文件夹、基于正则表达式过滤文件和目录,以及记住 .sln 文件中的映射。属性是非侵入性的,因此没有扩展的开发人员仍然可以打开 sln 而不会受到影响。

Hosted on visual studio gallery: https://visualstudiogallery.msdn.microsoft.com/69e19ea6-4442-4cb6-b300-044dd21f02bd

托管在视觉工作室画廊:https: //visualstudiogallery.msdn.microsoft.com/69e19ea6-4442-4cb6-b​​300-044dd21f02bd

Edit: Uploaded to bitbucket. Now open source. MIT license. https://bitbucket.org/LSS_NorthWind/physical-solution-folders

编辑:上传到 bitbucket。现在开源。麻省理工学院执照。https://bitbucket.org/LSS_NorthWind/physical-solution-folders