Using shared compilation with Roslyn in a standalone build environment?

We recently upgraded our build system from Update 2 from 2013 to 2015, and our build times have increased dramatically. Our build environment is autonomous, so we run MSBuild from the package (using devpath), and not from the installed location. Looking at the logs, it seems that increasing build time is almost everything in the csc build task. Installing MSBuild on the machine is not affected, although if we run from a fixed location and not from our standalone location, the build time is similar to what we see from 2013. When starting from a fixed location, we can see that joint averaging is used from the message "Using general compilation with the compiler from the directory: C: \ Program Files (x86) \ MSBuild \ 14.0 \ bin". At the moment, we have the impression that enabling general compilation will help with our build time, but we could not get it to work from our standalone environment. Setting "UseSharedCompilation" to true has no effect and does not result in the message above during build.

Is there a way to enable general compilation with Roslyn when starting MSBuild from a path other than the installed location?

+5
source share
2 answers

Have you tried overriding the "Csc" task? I evaluated a sample CSharp project from the command line using a preprocess (ie "/pp:out.txt"), opened "out.txt" and found that the only links to "UseSharedCompilation" are in one form or another, related to the build task of Csc.

Hitting the dark search for all text files on GitHub.com revealed E! true Hollywood story UseSharedCompilation. The following is the NuGet package "Microsoft.Net.Compilers":

<!-- The UsingTask, UseSharedCompilation, and ToolPath/Exe variables all interact to choose which compiler path to use and whether or not to use the compiler server. If UsingTask and UseSharedCompilation are set then the compiler server next to the task will be used (ie, the one in this package). If UseSharedCompilation is false or ToolPath/Exe are set the compiler server will not be used and the compiler exe at the ToolPath, if set, will be executed, otherwise the executable in the MSBuild install path will be executed. --> 

So, according to the above Xml comment, you will need to use some MSBuild tricksters to implement your standalone build environment using "UseSharedCompilation". For the full text of the above snippet, see https://raw.githubusercontent.com/dotnet/roslyn/c5b249b16f7d67ee1645a1b75fa3de6f16314672/build/NuGetAdditionalFiles/Microsoft.Net.Compilers.props .

+3
source

Turns out collaborative compilation was not our problem. Ultimately, we needed to run ngen.exe on csc.exe and most of the dll it depends on. This precompiles them, so JIT compilation is not performed for every exe call. Visual Studio does this when you install, but if you put them in a different directory, you have to do it again, as it searches for them by location. We just added a step when we opened an input window to start ngen on the necessary files, since it is pretty fast. Without it, csc.exe took about 10 seconds for each individual call.

+1
source

All Articles