简体   繁体   English

从C#运行Microsoft.Build.Evaluation.Project的并行构建

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

Good morning. 早上好。 Please help me with msbuild. 请帮我msbuild。

I have many loaded csproj in array of Microsoft.Build.Evaluation.Project. 我在Microsoft.Build.Evaluation.Project数组中加载了很多csproj。 I changed same properties in projects. 我在项目中更改了相同的属性。 How run parallel build of my projects? 如何运行我的项目的并行构建?

When I run project.Build() in many threads, I received exception "The operation cannot be completed because a build is already in progress." 当我在许多线程中运行project.Build()时,我收到异常“由于构建已在进行中,因此无法完成操作。” .

I can't save projects on disk, becouse I change property, that need only for me. 我不能在磁盘上保存项目,因为我改变了属性,只需要我。

You can call only one Build() function per process. 每个进程只能调用一个Build()函数。 So you need to synchronize all Build() call. 所以你需要同步所有的Build()调用。 Something like that: 像这样的东西:

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

...
ProjectBuildSync.Build(project);
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft.Build.Evaluation.Project 在VS中添加文件夹和文件强制刷新项目 - Microsoft.Build.Evaluation.Project add folder and file force refresh of project in VS 如何在MSBuild 14.0中重新加载Microsoft.Build.Evaluation.Project - How can I reload a Microsoft.Build.Evaluation.Project in MSBuild 14.0 为什么将 Xamarin Android.csproj 加载到 Microsoft.Build.Evaluation.Project 中会由于 missing.targets 文件而抛出 InvalidPropectFileException? - Why does loading a Xamarin Android .csproj into a Microsoft.Build.Evaluation.Project throw InvalidPropectFileException due to missing .targets file? C#从另一个项目建立一个项目 - c# Build a project from another project 如何使用 Microsoft.Build.Evaluation.Project.RemoveItem - How to use Microsoft.Build.Evaluation.Project.RemoveItem 使用Microsoft.Build.Evaluation.Project.RemoveItem删除的项目 - Removed item using Microsoft.Build.Evaluation.Project.RemoveItem 生成一个C#文件,但将其从项目中排除 - Build a C# file but exclude it from the project 使用Microsoft.Build.Evaluation发布数据库项目(.sqlproj) - Using Microsoft.Build.Evaluation to publish a database project (.sqlproj) 从dll构建C#项目 - Build C# project from dll 无法在 C# 中构建和运行测试:无法从 Microsoft.Build.CppTasks.Common 程序集加载“Xsd”任务,版本 = 12.0.0.0 - Cannot build and run test in C# : The “Xsd” task could not be loaded from the assembly Microsoft.Build.CppTasks.Common, Version=12.0.0.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM