Reduce Release build times

I’ll be talking about this in the context of a Sitecore implementation using the Helix pattern, but this is applicable to any .NET solution.

Within my solution I have many VS projects, all which reference third party nuget packages. Having the copy local of these references set to true for a build increases the build time; e.g. i reference “Newtonsoft.Json” in 30 projects, this one dll is built 30 times; it’s also part of the build artifacts of each.

I want to keep Copy Local set to true in my local debug build (debug purposes), so i can’t set this to false in Visual Studio’s references UI (i.e. the UI sets this for all build configurations).

Here is my solution: i will have one project with all my third party dll references. The other projects will have copy local set to false for these references, but only for the Release build; this can be done using a “.targets” filter file.

1) Add a “filter.release.targets” file to your solution to specify the dll’s to affect; this file removes the dll’s and then readds then with copylocal=false.

Here is a example:

2) Edit the csproj files that you want to apply this filter to, and add this line:

  <Import Project=“filter.release.targets” Condition=“ ’$(Configuration)|$(Platform)’ == ‘Release|AnyCPU’ ” />

This will only apply the copylocal=false when running a Release build.


In the context of Sitecore Helix:

I would have a Foundation project with my third party dependencies. Each Feature and Project would use the “.targets” file to remove these in Release builds. As I’m building and deploying all of these as separate nuget packages, this will reduce duplication of these dll’s in my build server artifacts and deployment nuget packages.