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

Map not Refreshing #55

Closed D3ADD3V3R closed 2 months ago

D3ADD3V3R commented 1 year ago

Hi, I have a solution with over 500 projects and more than 10 build configurations. The goal is to delete all build configurations except for the two default ones, and to do the same for the projects. I have read through Issue #3, and I can successfully remove the data from the SLN. However, when I look at “Map”, all the configurations are still there, and are saved again accordingly. Is there a way to update this map ?

I have attached my Code to this Request and will be thankfull for your help.

using var sln = new Sln(openFileDialog1.FileName, SlnItems.AllNoLoad | SlnItems.PackagesConfig);

sln.Result.SolutionConfigs.ToList().ForEach(c =>
{
    if (!(c.Configuration == "Debug" && c.Platform == "Any CPU") && !(c.Configuration == "Release" && c.Platform == "Any CPU"))
        ((SlnResult)sln.Result).SolutionConfigList.Remove(c);
});

((SlnResult)sln.Result).ProjectConfigList.ToList().ForEach(c =>
{
    if(!(c.Configuration == "Debug" && c.Platform == "Any CPU") && !(c.Configuration == "Release" && c.Platform == "Any CPU"))
        ((SlnResult)sln.Result).ProjectConfigList.Remove(c);
});,

var whandlers = new Dictionary<Type, HandlerValue>();

using (var w = new SlnWriter(openFileDialog1.FileName, whandlers))
{
    w.Write(sln.Result.Map);
}

Kind regards, Björn

3F commented 1 year ago

Hello,

> "when I look at “Map”, all the configurations are still there, and are saved again accordingly."

Because your whandlers are empty. You need just to link your runtime collection with related handlers then it should update. But first of all, I recommend also look at #42 Q&A for the related things. In particular, there I also noticed about "Any CPU" and "AnyCPU" to use at least MvsSln's default rules or implement its IRuleOfConfig in order to avoid problems for different environments.

tl;dr, try this:

string file = ...
using Sln sln = new(file, SlnItems.AllNoLoad);

bool _IsNot(IConfPlatform c)
     => !c.IsEqualByRule("Debug", "Any CPU")
     && !c.IsEqualByRule("Release", "Any CPU");

using SlnWriter w = new(file, new Dictionary<Type, HandlerValue>()
{
     [typeof(LSolutionConfigurationPlatforms)] = new(new 
WSolutionConfigurationPlatforms(
         sln.Result.SolutionConfigs.Where(c => _IsNot(c)))
     ),
     [typeof(LProjectConfigurationPlatforms)] = new(new 
WProjectConfigurationPlatforms(
         sln.Result.ProjectConfigs.Where(c => _IsNot(c.Sln)))
     ),

     [typeof(LProject)] = new(new WProject( // ... replica due to bug LC-102
         sln.Result.ProjectItems, sln.Result.ProjectDependencies)
     ),
});

w.Write(sln.Result.Map); // Now apply changes

Regarding to sln.Result items you need to see both #10 and #9 FYI, to refresh Map in 2.6 you need re-open the applied changes above.

n. I may still be very slow to respond due to many reasons beyond my control, sorry.

On 09.09.2022 11:31, Björn Ecke wrote:

Hi, I have a solution with over 500 projects and more than 10 build configurations. The goal is to delete all build configurations except for the two default ones, and to do the same for the projects. I have read through Issue #3 https://github.com/3F/MvsSln/issues/3, and I can successfully remove the data from the SLN. However, when I look at “Map”, all the configurations are still there, and are saved again accordingly. Is there a way to update this map ?

I have attached my Code to this Request and will be thankfull for your help.

using var sln = new Sln(openFileDialog1.FileName,SlnItems.AllNoLoad |SlnItems.PackagesConfig);

sln.Result.SolutionConfigs.ToList().ForEach(c =>

{

 if  (!(c.Configuration  ==  "Debug"  &&  c.Platform  ==  "Any CPU")&&  !(c.Configuration  ==  "Release"  &&  c.Platform  ==  "Any CPU"))

     ((SlnResult)sln.Result).SolutionConfigList.Remove(c);

});

((SlnResult)sln.Result).ProjectConfigList.ToList().ForEach(c =>

{

 if(!(c.Configuration  ==  "Debug"  &&  c.Platform  ==  "Any CPU")&&  !(c.Configuration  ==  "Release"  &&  c.Platform  ==  "Any CPU"))

     ((SlnResult)sln.Result).ProjectConfigList.Remove(c);

});,

var whandlers = new Dictionary<Type,HandlerValue>();

using (var w = new SlnWriter(openFileDialog1.FileName,whandlers))

{

 w.Write(sln.Result.Map);

}

Kind regards, Björn

Message ID: @.***>

3F commented 2 months ago

I close the issue because as I said you just need to update your runtime collections; then save the result into file or string.

Feel free to open an issue again if the problem still exists.