Replace external MSBuild processes with TaskHostFactory
#14700
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides a 70% improvement to build times within the Avalonia repository.
What does the pull request do?
Avalonia.Build.Tasks
is an MSBuild task assembly that is compiled at the start of every build. Its output assembly is then loaded by MSBuild for use by other solution projects.Because MSBuild processes are kept alive in anticipation of future builds, the tasks assembly remains loaded after a build completes. This means that its DLL file cannot be modified (on Windows, at least). The locked assembly file causes build errors if something about the
Avalonia.Build.Tasks
project changes and the file needs to be rebuilt.The current solution to this is to spawn an entirely new MSBuild process which spins up the entire project tree again, executes a specified target, then exits. This works, but is very slow, because MSBuild and the Avalonia project tree both take a considerable amount of time to load.
This PR replaces this system with
TaskHostFactory
. Like starting a new MSBuild process, this isolates the use of theAvalonia.Build.Tasks
assembly to a short-lived process. Unlike starting a new MSBuild process, only the task and its immediate inputs are loaded. This is much, much faster.The build time improvements also apply to design-time builds within Visual Studio. The IDE is now more responsive and completes loading the solution sooner.
Errors after switching to this branch
Please note that due to Visual Studio's project caching behaviour, you may encounter file locking errors after switching to this PR's branch with the Avalonia solution already loaded. Restarting the IDE will fix this. It's not a problem with the PR itself, and will stop being an issue once the changes are on master and spread to other branches.
The PR's changes can be easily validated under normal development circumstances by making a change to
Avalonia.Build.Tasks
and building the solution again.What is the updated/expected behavior with this PR?
When building Avalonia.Desktop.slnf:
Breaking changes
None.
This entire subject only affects builds of the Avalonia repository, not builds of projects which consume Avalonia's Nuget packages. Package builds have always loaded the build tasks assembly normally, and continue to do so.
Obsoletions / Deprecations
None