After a lot of reading and wading through finnicky solutions to this problem, it’s bizarre that projects are structured in this way and yet there doesn’t seem to be a straight forward way of creating it.
A brilliant example is Microsoft’s eShopOnContainers project – https://github.com/dotnet-architecture/eShopOnContainers
The repository has a physical src folder, when you open the eShopOnContainers-ServicesAndWebApps.sln – the solution explorer displays the src as if it were a logical folder.
I find that the .sln also lives in a peculiar place – directly within the src folder, it’s almost like this .sln has been created manually and projects added to it as necessary.
The same is the case with the Services folder and its contents, each project lives as Services/Identity/Identity.API – this full structure displays in both file explorer and solution explorer, but when I attempt to recreate this I can 1 of 2 scenarios –
- I create the folder structure as physical folders and they do not display in the solution explorer.
- I create the folder structure as logical/solution folders and they do not display in the file explorer.
This doesn’t seem possible via the projection create GUI, I imagine this has been done by creating the projects and structure via the dotnet CLI, but I can’t seem to figure it out, how is this done?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The solution to this via the Visual Studio GUI –
Create your logical folder structure as you see fit within Visual Studio, and then to have your physical folders match that structure – or even differ from it – create the path along with the project which you are creating, the file system will create the physical folders from the specified path and you will have achieved the desired effect.
Example:
Create C:myprojectsrc
Visual Studio -> File -> New -> Project -> Blank Solution (name: myprojectsolution)
Right click myprojectsolution -> Add -> New Solution Folder (name: src)
My the myprojectsolution.sln into C:myprojectsrc then delete the myprojectsolution folder which was created with the .sln file.
Logical and Physical folders are now matching, the .sln lives directly in src, and src will display in the solution explorer.
At this point, let’s say you want to create an Identity.IDP project at MicroservicesIdentityIdentity.IDP, with a matching logical and physical structure.
Visual Studio -> right click src -> Add -> New Solution Folder (name: Microservices)
Visual Studio -> right click Microservices -> Add -> New Solution Folder (named: Identity)
Visual Studio -> right click Identity -> Add -> New Project (name: Identity.IDP, location: C:myprojectsrcMicroservicesIdentity)
The above will result in a matching folder structure existing in both the solution explorer and the file explorer.
In summary – create your solution structure via the Visual Studio GUI, create your physical structure via specifying the path when creating the project.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0