Visual studio solution folder at the project level

2020-07-09 07:12发布

问题:

In Visual Studio (2010) is it possible to create a "Solution Folder" at the project level?
A "virtual" project folder within Visual Studio?

The problem:

We have a project in our solution which contains all our culture resource files. We employ a single resource file per business purpose, i.e. we have more than one resource file representing each culture.

As resource files for different cultures have to be stored at the same location (path) this results in or project containing many resource files at the root level. This is fine for the time-being but as we add support for different cultures the number of resource files will grow to an unmanageable number

So in order to better organize our project we'd like to create a "virtual" folder at the project level where we can create one folder per culture. Is this possible?

Any thoughts?

回答1:

I'm pretty sure you can't. This has always been a odd nuance to me of VS, that the folders in solutions are virtual, yet the Project folders are not. I don't like the virtual folders anyways, because you can run into strange nuances because your physical moving of files doesn't stay in sync with the structure in the virtual folders. Has caused me headaches. I've always wished there were physical folders at the solution level for putting things shared across projects.

Step 1) If they just need to be all in the same physical folder, then to start with I would move them into a Resources subfolder of the project. I keep very little in the root of my projects. Even source code goes into a "src" folder. Leaving only things like *.config files in the root.

Step 2) Create several virtual folders as needed at the solution level where you drag the files from the project into it's appropriate virtual solution folder. The file will still physically exist and show in the "Resources" folders at the project, but for more user friendly browsing of the files, they will exist in the virtual folders which just references the original file.

I realize this is less than ideal, but thought I'd point out that nothing is stopping you from using the solution level folders while having the files exist physically in the project.

But as I mentioned, if you add new resources files to your project, you will always need to take that extra step of "categorizing" them by dragging them into a virtual solution folder. This is one of those things that is likely to get out of sync because you will forget about these if you go a few weeks without touching this project.

A better solution might be to use some sort of custom build step, maybe with nant or msbuild, that takes Resources stored in phyiscally seperate resource folders and copies them into a single resource folder before compilation. This way you create resources in each subfolder, and the build step automatically copies them into the single destination folder.