Run parallel build of Microsoft.Build.Evaluation.Project from C #

Good morning. Please help me with msbuild.

I have many loaded csprojs in a Microsoft.Build.Evaluation.Project array. I changed the same properties in projects. How to build my projects in parallel?

When I run project.Build () on many threads, I got the exception "Operation could not be completed because the assembly is already in progress." .

I cannot save projects to disk because I am changing the property that is needed only for me.

+3
source share
1 answer

Build() . Build(). - :

static class ProjectBuildSync
{
    private static readonly object _syncObject = new object();
    public static bool Build(Project project)
    {
        lock (_syncObject)
            return project.Build();
    }
}

...
ProjectBuildSync.Build(project);
...
+1

Source: https://habr.com/ru/post/1786127/


All Articles