Skip to content
Denis Kuzmin (github/3F) edited this page May 1, 2024 · 1 revision

Since the 1 project instance means only the 1 project with specific project configuration and platform, you must work with each instance separately if this project has 2 or more of this. Usually project has at least Debug and Release for specific platform (depending on the project type).

In its turn, each project configuration is associated with a solution configuration, same with the mentioned config and platform name pair.

All this can be represented as a Cartesian product of two sets Projects configurations (P) and Solution configurations (S). Therefore, the maximum possible configurations for such projects are calculated as P * S. That is, all P * S can be loaded as each different instances.

So when you try to load .sln file with EnvWithProjects (or similar to) this will cause an attempt to load all defined set. But in fact, mostly 2 or more project-configuration can be related to the same 1 solution-configuration, therefore it can be only half or a quarter or even less of the possible combinations.

The point of different instances is that when data is loaded, all their nodes must be evaluated before final use. Imports, Items, Targets, Tasks, Properties, ... all types of these nodes can have their own conditions, properties, and also certain values depending on other states that can refer to other nodes and so on deeper and deeper and this whole process can only be true for a specific configuration P1. While P2 will do different processing due to different original input data.

In reality, the use is simpler since in most cases only general data is needed (intersecting or accessible between Pn). That's why you have the option to load any available using IEnvironment.LoadMinimalProjects() or EnvWithMinimalProjects flag.

Or, for example, use IEnvironment.LoadProjects()

// SlnItems.Env will initialize environment without loading projects.
using(var sln = new Sln("Input.sln", SlnItems.Env))
{
    ISlnResult sr = sln.Result;

    // get the first available solution configuration
    IConfPlatform slnCfg = sr.SolutionConfigs.FirstOrDefault();

    // only for specified solution configuation ^
    sr.Env.LoadProjects(
        sr.ProjectItemsConfigs.Where(p => p.solutionConfig == slnCfg)
    );
}

Which is generally convenient to use for gradually loading what is needed at the moment, for example: https://github.com/3F/MvsSln/discussions/49

using Sln sln = new("Input.sln", SlnItems.Env);

sln.Result.Env
    .LoadProjects(sln.Result.ProjectItemsConfigs.Where(p => p.project.IsCs()))
    .ForEach(xp =>
    {
        xp.AddItem("Compile", @"financial\Invoice.cs");
    });
Clone this wiki locally