Visual Studio Solutions Folder as real Folders

2019-01-07 10:12发布

问题:

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

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.

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?

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

回答1:

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.



回答2:

There is a workaround, that actually behaves as expected.

  1. Add a New or Existing Web Site to 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!

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.

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?



回答3:

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. .



回答4:

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.



回答5:

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.



回答6:

I've wanted this feature a few times myself, but at the end of the day, you really do NOT want the ability to do this. Think of your Solution (file) as as the root of a web application and think of Solution folders as Virtual Directories (literally and functionally). The contents of a web virtual directory could be physically on a different server altogether. Where Visual Studio muddled up the solution folders concept is by allowing you to create new files inside the folder. You should always "Add Existing" when adding content. When you add existing, it creates a link to the source location of the file.

But as for the reason you do not want solution folders to behave like "physical" folders is because your solution layout may not necessarily use the same convention as your source control layout. Solution folders allow you to customize the hierarchy of your projects so that you can group projects and items together any way you like, and then decide you don't like it and change it again without having to go through the nightmare of moving source control items around and irritating the rest of your team.



回答7:

Folder To Solution Folder By 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.



回答8:

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...

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.

Congrats you are done..

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



回答9:

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.

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.

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

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



回答10:

The folder created underneath the solution will be virtual as said. Maybe this might be called a workaround but you can physically create the folder on disk either before or when you add new item/project and Robert should be a sibling of your dad.

ps- on closer look maybe i should explain "bob's your uncle" means your fine/sorted.



回答11:

You can add real folders by choosing "Add new filter" for a Visual Studio project file. You can also do "Add new filter" under an existing folder. Once the folder is created, rename it and add source or header file or whichever suits your project. This is one way I know which lets us create real folders through the Visual Studio IDE.



回答12:

I have a bit of a workaround for this (it's not great, but it works).

  1. Create a folder in your solution (i.e. "Contoso")
  2. Right click on the solution and then click "Open Folder in Solution Explorer"
  3. Create the physical folder (i.e. "Contoso") in the solution directory
  4. Copy/Create files in the physical folder.
  5. Drag the files into the virtual folder in the solution explorer.

It's not great because you will need to manually maintain the file references, but it works for me.



回答13:

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.