I've noticed that the build time is exponentially slower in my new .NET Core project than in previous projects written in .NET Standard 4. I tried a number of other solutions mentioned on here to no avail.
I had a "eureka" moment and finally tracked down the problem to having enabled nullable reference types in the project (.csproj) file.
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;Stage</Configurations>
</PropertyGroup>
I didn't want to disable the feature but I also don't need my build times taking minutes instead of seconds. To workaround this issue, I added a condition to my .csproj file to set nullability to false when performing a debug build inside Visual Studio:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;Stage</Configurations>
</PropertyGroup>
<!-- Disable nullable checks on debug build (fixes slow build issue) -->
<Target Name="DisableNullableForVisualStudioBuild"
BeforeTargets="CoreCompile"
Condition="'$(BuildingInsideVisualStudio)' == 'True' And '$(BuildingProject)' == 'True' And '$(Configuration)' == 'Debug'">
<PropertyGroup>
<Nullable>disable</Nullable>
</PropertyGroup>
</Target>
Voila, problem solved! This of course does have the unfortunate side effect of not having the compiler provide me warnings inside the Output panel regarding nullables, but I still get Intellisense warnings in real-time, so for me it's an acceptable compromise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With