3F / MvsSln

🧩 Customizable VisualStudio .sln parser with project support (.vcxproj, .csproj., …). Pluggable lightweight r/w handlers at runtime, and more …
MIT License
135 stars 27 forks source link

Create Solution Folder #6

Closed OneManMonkeySquad closed 5 years ago

OneManMonkeySquad commented 5 years ago

Hello,

as far as I can see, I can't create new project folders or assign projects to folder. Our build system generates a flat list of 400 C++ projects and I want to categorize them.

3F commented 5 years ago

Solution Folders(items) are possible through:

    IEnumerable<SolutionFolder> SolutionFolders

So you can try to create new folder and/or its items in the same manner like from my example here.

Let me know if you can't something, I'll prepare some example later.

OneManMonkeySquad commented 5 years ago

Any clue on how to get the NestedProjects section populated?

GlobalSection(NestedProjects) = preSolution
    {9E2D0B92-DA21-418C-9F9A-3C896110B992} = {2E05BAA3-EB03-46F9-8C52-232DB0D837EB}
EndGlobalSection

SolutionFolder takes a list of RawTexts for single files, but no projects? Quick hint please :D Also, seems I'm not properly writing the sln. The writer duplicates all project decls.

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "src\Core\Core.vcxproj", "{E075AD0E-2E65-3CFD-9E5E-C07B9CDDF9E3}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "src\Core\Core.vcxproj", "{E075AD0E-2E65-3CFD-9E5E-C07B9CDDF9E3}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "src\Core\Core.vcxproj", "{E075AD0E-2E65-3CFD-9E5E-C07B9CDDF9E3}"
3F commented 5 years ago

Today's way for creating solution folder looks like:

var folders = new List<SolutionFolder>(sln.Result.SolutionFolders)
{
    new SolutionFolder
    (
        new ProjectItem()
        {
            pType = Guids.SLN_FOLDER,
            name = "MyFolder1",
            path = "MyFolder1", // recommended to be same
            pGuid = Guid.NewGuid().ToString()
        },
        new List<RawText>()
        {
            ".gnt\\gnt.core",
            ".gnt\\packages.config",
            // ...
        }
    ),
    //...
};

handlers for this case as I said:

var whandlers = new Dictionary<Type, HandlerValue>() {
    [typeof(LProjectSolutionItems)] = new HandlerValue(new WProjectSolutionItems(folders)),
};

But seems we have no handlers for NestedProjects when solution folders, sorry for the inconvenience :(

I've plan to implement this, follow the news.

3F commented 5 years ago

Any clue on how to get the NestedProjects section

ah yes, forgot to say about map. I don't recommend this, but anyway, just for clarify before support.

In any case, you can easily get access to any lines of loaded .sln.

As it was illustrated:

The Map property from result contains all lines which are already processed with handlers and which are still not.

So we can get anything to manual processing. However, this is not recommended way.

Because I specially prepared flexible architecture to add any custom handlers (including user space) for any lines which are still not processed (or for multiple processing).

Thus, temporarily you can try to add your custom handler, then just register it in listeners for common use.

I think we need also add some documentation for this <_<

But of course, MvsSln should support this by default. Ticket above.

OneManMonkeySquad commented 5 years ago

Thank you for your quick answer :)

I decided to implement this with a rather long python script. It's crude but it does the job. A list of things to consider when implementing this might help you:

3F commented 5 years ago

It will be implemented later anyway. At least by me.

In fact, the main features was extracted from vsSolutionBuildEvent project. Mainly for DllExport, but I also had plans in past for just splitting something like this including its script engine etc.

That is, this feature was simply not required to someone(including me) for all that period :)

But MvsSln should really cover it. Basically, we just need to implement ISlnHandler and IObjHandler with related logic for new handlers. It shouldn't be hard.

I will look into later. More probably this March, well, as possible for my time. Also follow the new issue.

3F commented 5 years ago

You can test new features starting from CI-build-37 https://github.com/3F/MvsSln/releases

Planned for 2.2

new SolutionFolder("dir1", 
    new SolutionFolder("dir2", 
        new SolutionFolder("dir3", "hMSBuild.bat", "DllExport.bat")
    )
);
...
new ProjectItem("Project1", ProjectType.Cs, new SolutionFolder("dir1"));

https://github.com/3F/MvsSln/issues/8#issuecomment-478596679

@SirPolly

getting or creating a folder with the same method (GetOrCreateFolder)

More probably it's beyond of this project. You can easily use it manually from your app. However, you also can create new issue for suggest this feature. It will be considered later.