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

How to create a solution from scratch? #33

Closed Str1ker17 closed 3 years ago

Str1ker17 commented 3 years ago

The title is the question itself

3F commented 3 years ago

As I mentioned in #3, the basic principles are map and data using active collections. The only thing is that 2.5.x does not provide a better ways around data from scratch. But it would be considered later I think.

However, even today it is still quite simple, for example:

// provide some data; it can be either other processed .sln or from scratch, etc.

    // for example, some headers ~
    var header = new SlnHeader();
    header.SetFormatVersion("12.0");
    header.SetMinimumVersion("10.0.40219.1");

    // some project collection from scratch ~
    var projects = new[] { new ProjectItem("MyProject", ProjectType.Cs, "path") };

    // ... and so on;

// then prepare write-handlers related to your data, eg.:
var whandlers = new Dictionary<Type, HandlerValue>()
{
    [typeof(LVisualStudioVersion)] = new HandlerValue(new WVisualStudioVersion(header)),
    [typeof(LProject)] = new HandlerValue(new WProject(projects, new LProjectDependencies())),
};

// commit this
using var w = new SlnWriter("result.sln", whandlers);
w.Write(new[] // for 2.5.x only manual mapping from scratch like here
{
    new Section(new LVisualStudioVersion(), null),
    new Section(new LProject(), null)
});

result.sln

Microsoft Visual Studio Solution File, Format Version 12.00
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyProject", "path", "{CD128011-5F3E-4A88-A2D2-24A1E4DCD580}"
EndProject