在自包含的构建环境中使用与Roslyn的共享编译?

Jpe*_*igo 5 roslyn

我们最近将构建系统从VS 2013升级到2015 Update 2,我们的构建时间也大幅增加.我们的构建环境是自包含的,因此我们从包(使用devpath)而不是从已安装的位置运行MSBuild.看一下日志,看起来构建时间的增加几乎都在csc构建任务中.在机器上安装MSBuild没有任何影响,但如果我们从安装的位置而不是我们自包含的位置运行,则构建时间与我们在2013年看到的类似.从安装位置运行时,我们可以看到共享的compliation正在使用消息" 使用共享编译与目录中的编译器:C:\ Program Files(x86)\ MSBuild\14.0\bin ".目前我们的印象是,启用共享编译将有助于我们的构建时间,但我们无法从我们自包含的环境中获得它.将"UseSharedCompilation"设置为true没有任何影响,并且在构建期间不会导致上面的消息.

有没有办法在从安装位置以外的路径运行MSBuild时启用与Roslyn的共享编译?

小智 3

您是否尝试过完全覆盖“Csc”任务?我使用预处理(即“/pp:out.txt”)开关从命令行评估了一个示例 CSharp 项目,打开“out.txt”,发现对“UseSharedCompilation”的唯一引用是一种形状或与 Csc 构建任务相关的另一个。

在 GitHub.com 上的所有文本文件中进行暗中搜索发现了 E!UseSharedCompilation 的真实好莱坞故事。以下内容来自 NuGet 包“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 (i.e., 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. -->
Run Code Online (Sandbox Code Playgroud)

因此,根据上面的 Xml 注释,您将不得不采用一些 MSBuild 技巧来通过“UseSharedCompilation”实现您的独立构建环境。有关上述代码段的全文,请参阅https://raw.githubusercontent.com/dotnet/roslyn/c5b249b16f7d67ee1645a1b75fa3de6f16314672/build/NuGetAdditionalFiles/Microsoft.Net.Compilers.props。