MSBuild ver.16 runs hundreds of MSBuild processes when MaxNodeCount is greater than 1

老子叫甜甜 提交于 2021-02-08 08:21:40

问题


We have an application, which builds and prepares a "deploy package" of our ASP.NET applications. It had references to the .NET Framework MSBuild, which was working fine. Few weeks ago we started to use VS2019 instead of VS2015. Because of some NuGet packages we had to update this application with latest MSBuild, which is now part of the VS and not in GAC anymore. I did that using this documentation. And then the fun began... :/ I found out that the problem lies in BuildParameters.MaxNodeCount property:

  • If I set it's value to 1, everything works fine but far slower than before the update.
  • If value is set to something greater than 1 (I set it to Environment.ProcessorCount), literaly hundreds of MSBuild processes are started. Sometimes it works but most of the time it fails with outofmemory exception. Sometimes even OS collapses and needs to be restarted.

Picture of lots of MSBuild processes

Picture of MSBuild error

Before the update BuildProperties.MaxNodeCount was set to Environment.ProcessorCount and everything worked fine.

Any idea what could cause this kind of behaviour? Why property MaxNodeCount is not taken into account?

Edit 1:

Code, that invokes MSBuild API:

Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
GlobalProperty.Add("Platform", "Any CPU");
GlobalProperty.Add("Configuration", "Release");
GlobalProperty.Add("TargetFrameworkVersion", "v4.8");
GlobalProperty.Add("DeployOnBuild", "true");
GlobalProperty.Add("PublishProfile", "passed_as_input_parameter");
GlobalProperty.Add("AspnetMergePath", "passed_as_input_parameter");

BuildResult buildResult;
FileLogger fl = new FileLogger()
{
    Parameters = @"logfile=log_file_path;append=true",
    Verbosity = LoggerVerbosity.Normal
};

BuildParameters bp = new BuildParameters()
{
    Loggers = new List<Microsoft.Build.Framework.ILogger> { fl }.AsEnumerable(),
    DetailedSummary = false,
    OnlyLogCriticalEvents = false,
    ShutdownInProcNodeOnBuildFinish = true,
    MaxNodeCount = Environment.ProcessorCount
};           
            
BuildRequestData br;
br = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Clean", "Rebuild" }, null);

buildResult = BuildManager.DefaultBuildManager.Build(bp, br);

来源:https://stackoverflow.com/questions/62658963/msbuild-ver-16-runs-hundreds-of-msbuild-processes-when-maxnodecount-is-greater-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!