Search code examples
c#asp.netyeomansolutionsln-file

How do I manually add Solution folders to a .sln file?


Say I have a solution that is structured like so:

|__TopLevelFolder
     |___ModuleFolder
         |____ProjectFile
         |____TestProjectFile

I want to create another "ModuleFolder" under "TopLevel" and add its corresponding project and test project files. However, for my purposes I have to manually modify the .sln file to add them (I am doing this as part of a yeoman generator meaning I can't do this in VS like normal).

My problem is that when I modify the .sln file, my folder appears as an unavailable project, and when I try to reload it, the load fails and it says "The project file or web cannot be found." Here is what I'm doing in the .sln file:

First I add the folder:

Project("{GUID}") = "NewModuleFolder", "NewModuleFolder", "{NewModuleGUID}"
EndProject

Then I add the actual project:

Project("{GUID}") = "TopLevel.NewModule.Tests", "src\TopLevel\NewModule\TopLevel.NewModule.Tests.csproj", "{TestProjectGUID}"
EndProject

Then in the "preSolution" section I add a line which places the NewModuleFolder underneath the TopLevelFolder as well as the TestProject underneath the NewModuleFolder:

GlobalSection(NestedProjects) = preSolution
    {NewModuleGUID} = {TopLevelGUID}
    {TestProjectGUID} = {NewModuleGUID}
    ...
EndGlobalSection

This is exactly how all the other folders and projects work in my solution (believe me I double and triple-checked as well as tried switching GUIDs around to make sure).

Any ideas on how to make this work or what I'm doing wrong (or a different way I should be doing this considering I'm creating a yeoman generator)?

Thanks!!


Solution

  • Guid for project type must be "2150E333-8FDC-42A3-9474-1A3956D46DE8", second guid should be just new guid.

    Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = 
          "MyFolder", "MyFolder", "{C990590A-798B-41BB-9A2A-50D28037BA2A}"
       ProjectSection(SolutionItems) = preProject
            MyFolder\some.txt = PysicalPath\a.txt
       EndProjectSection
    EndProject
    

    See Where are Visual Studio 2013 Solution Folders? for some more info.