简体   繁体   English

使用“ Microsoft.CodeDom.Providers.DotNetCompilerPlatform”包时,csc.exe编译时间降低

[英]csc.exe compilation time degradation when “Microsoft.CodeDom.Providers.DotNetCompilerPlatform” package is used

Our team is currently migrating from C# 5.0 to C# 6.0 syntax so Roslyn compiler should be used instead of the legacy one. 我们的团队目前正在从C#5.0迁移到C#6.0语法,因此应使用Roslyn编译器而不是旧版编译器。

We have to use "csc.exe" as a part of the complex solution compilation process. 我们必须在复杂的解决方案编译过程中使用“ csc.exe”。 Build commands look like this: 生成命令如下所示:

c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe -nologo -target:library  -out:c:\repo\bin64\deb\common.dll @.\rspE0FF.tmp

This command execution takes ~400ms 该命令执行大约需要400ms

"rspE0FF.tmp" content looks like this (it contains much more *.cs files, however, it does not matter, this is reproducible on any set of files): “ rspE0FF.tmp”内容看起来像这样(它包含更多* .cs文件,但是,没关系,这在任何文件集上都可以重现):

"c:\repo\shared\common\estimation\complexjob.cs"
"c:\repo\shared\common\stringdecorator.cs"
"c:\repo\shared\common\tplextensions.cs"
"/reference:mscorlib.dll" "/reference:System.dll" "/reference:System.Data.dll" "/reference:System.Xml.dll" "/reference:System.ServiceModel.Activation.dll" "/reference:System.IdentityModel.dll" "/reference:System.Data.Entity.dll" 

When Roslyn compiler is used execution time shouts to ~4100ms Command is the same just csc.exe is called from the package folder: 当使用Roslyn编译器时,执行时间喊到〜4100ms。命令是相同的,只是从包文件夹中调用csc.exe:

c:\NewRepo\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\tools\RoslynLatest\csc.exe -nologo -target:library -out:c:\repo\bin64\deb\common.dll @.\rspE0FF.tmp

We have to build the solution by sequentially running hundreds of csc.exe commands like this. 我们必须通过依次运行数百个csc.exe命令来构建解决方案。 Total compilation time has grown from 2 minutes to 8 minutes. 总编译时间从2分钟增加到8分钟。

Is this performance degradation expected? 是否会导致性能下降?

Any advice on how to tweak this? 关于如何进行调整的任何建议?

The roslyn team does not consider someone invoking csc.exe as part of its perf investigations. roslyn团队不认为有人调用csc.exe作为其perf调查的一部分。 Today you are jitting all of csc.exe on each invocation (see here for more info). 今天,您将在每次调用时将所有csc.exe压缩(有关更多信息,请参见此处 )。

Possible solutions: 可能的解决方案:

  • run ngen on the version of csc you are using so hopefully you only need to JIT once 在您使用的csc版本上运行ngen,因此希望您只需一次JIT
  • use the compiler server, which in addition to re-using csc instances also caches metadata across builds. 使用编译器服务器,该服务器除了重复使用csc实例外,还可以在各个版本之间缓存元数据。

NOTE: the msbuild task does this automatically for you, but in your case you will need to do this manually. 注意:msbuild任务会自动为您执行此操作,但是,根据您的情况,您将需要手动执行此操作。

You would need to setup the server (duplicate what this code is doing) and pass /server to all of your csc calls 您将需要设置服务器(复制代码的作用),然后将/server传递给所有csc调用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在没有 nuget package 的情况下使用 Microsoft.CodeDom.Providers.DotNetCompilerPlatform? - Is there a way to use Microsoft.CodeDom.Providers.DotNetCompilerPlatform without a nuget package? Microsoft.CodeDom.Providers.DotNetCompilerPlatform 的问题 - Problem with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 无法加载文件或程序集“Microsoft.CodeDom.Providers.DotNetCompilerPlatform 或其依赖项之一。” 访问被拒绝 - Could not load file or assembly 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform or one of its dependencies. Access is denied 无法找到CodeDom提供程序类型“Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider ...” - The CodeDom provider type “Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider …” could not be located "找不到 CodeDom 提供程序类型“Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider”" - The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider" could not be located 解决C#CodeDom在csc.exe中导致堆栈溢出(CS1647)的问题? - Work-around for C# CodeDom causing stack-overflow (CS1647) in csc.exe? 使用csc.exe时的编译器警告CS1701 - Compiler Warning CS1701 when using csc.exe csc.exe在地球上哪里? - Where on Earth is csc.exe? 编译时,CSC.exe抛出“进程由于StackOverflowException而终止” - CSC.exe throws “Process is terminated due to StackOverflowException” when compiling 使用 csc.exe 构建时访问内部异常 - Accessing inner exceptions when building using csc.exe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM