In a recent Twitter thread, Drew Noakes from Microsoft announced some really great features that were added to Visual Studio 2022 – V 17.5. They are all great, but especially one took my attention which will will test for ourselves on this blog post.
It seems that Visual Studio 17.5 supports a feature named BuildAcceleation which could improve the build time of your projects by 80%!!
Drew writes that “The savings come from only building projects that were actually modified, so you don’t pay (in build time) for what you don’t change. Let’s see what that means…”. He then continues by writing that “This means build time is primarily spent on the compilation, rather than post-compilation housekeeping. Or for those who like big-O notation, build times are O(projects changed) rather than O(projects changed * project graph depth)….”
Visual Studio Update
The first step to test the performance feature would be to update Visual Studio to the latest version, which currently is V 17.5.0
Project
To test this new feature I will be using an existing project, from my GitHub repositories. In a folder of your choice use the following command to clone this project:
git clone https://github.com/etrupja/complete-ecommerce-aspnet-mvc-application
after you clone this project, check out the latest branch which is 97e as that is the branch with the most code. You can also use another project if you have any.
Testing
Now, it is time to test the build time. I will first build this project without updating any visual studio code or doing anything. You can either use a shortcut CTRL + SHIFT + B or you can use Visual Studio, Build > Build Solution. This is going to trigger a build
You can see that the build time for this project was 09.844 seconds. This is a relatively small project, but we will run another test with a larger project.
Now, let us enable Build Acceleration in Visual Studio. For that you need to add property named AccelerateBuildsInVisualStudio and set the value to TRUE.
To enable it on the solution level set the property in a Directory.Build.props file which you have created in your solution root.
This is how my Solution file looks like (Right click > Edit)
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net5.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.6"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup> </Project>
Here I will add a new section:
<PropertyGroup> <AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio> </PropertyGroup>
The complete file now looks like the below:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net5.0</TargetFramework> </PropertyGroup> <PropertyGroup> <AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.6"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup> </Project>
Now, let us build the project and check out the build time:
I did clean my solution and did another build. It now took only 03.445 seconds.
Another Test
I will run another test with a larger solution which includes multiple projects. This is an enterprise project and I can not share the code with you, but you can definitely download some larger projects from GitHub and test it for yourself.
The build results of the new project before adding AccelerateBuildsInVisualStudio are as below:
========== Build: 23 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== ========== Build started at 8:10 PM and took 02:10.236 minutes ==========
and if you do a rebuild without cleaning up the solution this is the result:
========== Build: 4 succeeded, 0 failed, 19 up-to-date, 0 skipped ========== ========== Build started at 8:29 PM and took 13.661 seconds ==========
Now, I will add AccelerateBuildsInVisualStudio to the solution, and clean and rebuild the solution. The results are as below:
========== Build: 22 succeeded, 0 failed, 1 up-to-date, 0 skipped ========== ========== Build started at 8:22 PM and took 01:14.096 minutes ==========
and if you do a rebuild without cleaning up the solution this is the result:
Build started... ========== Build: 0 succeeded, 0 failed, 23 up-to-date, 0 skipped ========== ========== Build started at 8:24 PM and took 00.511 seconds ==========
As you can see from the tests above, adding AccelerateBuildsInVisualStudio to your solution or your project does improve the build time by a lot.
Image by pressfoto on Freepik