Skip to content
Denis Kuzmin [ GitHub/3F ] edited this page Oct 12, 2019 · 5 revisions

Advanced Features

Custom loading of projects

MvsSln provides related virtual methods for your convenience since we're still using the original MS implementation for work with project files.

As the real example, the .NET DllExport project uses this way to avoid some problems when loading unsupported project types:

That is, you can easily try to override actual loading with any custom logic as you need. For example:

+Microsoft.Build.dll //  ~ it could be custom reference in your env

using net.r_eg.MvsSln;
using net.r_eg.MvsSln.Core;
...

public class MyEnv: IsolatedEnv, IEnvironment, IDisposable
{
    public MyEnv(ISlnResult data)
        : base(data)
    {

    }

    protected override Microsoft.Build.Evaluation.Project Load(string path, IDictionary<string, string> properties)
    {
        return base.Load(path, properties); //TODO: your awesome logic 
    }
    
    protected override void Dispose(bool disposing) => base.Dispose(disposing);
}
...

Please note: 2.4 introduces XProjectEnv (spitted IsolatedEnv as the base but without IDisposable) [?]

Now, just provide your implementation for MvsSln. For example:

using(var sln = new Sln(file, SlnItems.Projects
                                | SlnItems.SolutionConfPlatforms
                                | SlnItems.ProjectConfPlatforms))
{
    IEnvironment env = new MyEnv(sln.Result);
    env.LoadMinimalProjects();
    ...

    sln.Result.ProjectItems.Where(p => p.path == "special\\projectfile.csproj");
    ...
}
Clone this wiki locally