Improve MSBuild Performance by Adjusting CPU Priority
Summary
I frequently build, run, and rebuild an MVC application on Windows 11 using my office laptop. To improve build performance, I’ve found that manually adjusting the CPU priority for MSBuild.exe to High (via Task Manager or PowerShell) significantly reduces build times.
Is there a built-in way to configure MSBuild to always run with High CPU priority—either globally, from within Visual Studio, or via an MSBuild setting?
I currently use a PowerShell script to set MSBuild’s priority to High:
while ($true) {
$processes = @(
'MSBuild',
'devenv',
'ServiceHub.Host.dotnet.x64',
'ServiceHub.RoslynCodeAnalysisService'
)
foreach ($processName in $processes) {
Get-Process $processName -ErrorAction SilentlyContinue | ForEach-Object {
$_. PriorityClass = 'High'
}
}
Start-Sleep -Seconds 5
}
Background and Motivation
Building and rebuilding my MVC application frequently on Windows 11, I’ve noticed that manually setting MSBuild.exe to High CPU priority significantly reduces build times.
Proposed Feature
Provide a built-in option to configure MSBuild to always run with High CPU priority, either globally, within Visual Studio, or via an MSBuild setting.
Alternative Designs
A possible alternative is using an external script (e.g., PowerShell) to adjust MSBuild's process priority each time it runs, but this is not as seamless as a built-in solution.
Hi @RezaRahmatzadeh,
After the team triage, we agreed to close the ticket since it doesn't fit a general windows model for handling the priorities. We would recommend you to run devenv.exe with bumped priority and all spawns processes would inherit it.
Hi @RezaRahmatzadeh,
After the team triage, we agreed to close the ticket since it doesn't fit a general windows model for handling the priorities. We would recommend you to run devenv.exe with bumped priority and all spawns processes would inherit it.
Thanks for your suggestion @YuliiaKovalova , when I tried to set devenv.exe to high after that I realized msbuild is not getting high priority so I needed to set them to high separately, setting msbuild to high fasting build process very remarkable.
This matches my experience as well - MSBuild seems to set its own priority rather than inheriting from devenv.exe, which is why explicitly setting MSBuild to high priority gives such noticeable performance improvements during builds.
Hi @RezaRahmatzadeh, After the team triage, we agreed to close the ticket since it doesn't fit a general windows model for handling the priorities. We would recommend you to run devenv.exe with bumped priority and all spawns processes would inherit it.
Thanks for your suggestion @YuliiaKovalova , when I tried to set devenv.exe to high after that I realized msbuild is not getting high priority so I needed to set them to high separately, setting msbuild to high fasting build process very remarkable.
This matches my experience as well - MSBuild seems to set its own priority rather than inheriting from devenv.exe, which is why explicitly setting MSBuild to high priority gives such noticeable performance improvements during builds.
let's ask @rainersigwald if he knows why it could happen
https://learn.microsoft.com/en-us/windows/win32/procthread/scheduling-priorities:
If the calling process is IDLE_PRIORITY_CLASS or BELOW_NORMAL_PRIORITY_CLASS, the new process will inherit this class.
This seems to mean HIGH_PRIORITY_CLASS is not inherited by child processes.
Huh, TIL!
However, I don't expect to add this option--it doesn't reliably improve performance for builds when we've tried it in the past, and spawning a bunch of high-pri processes is a great way to make a machine feel laggy and unusable.