我正在关注此处的文档Setting Up for Microsoft C# Development,在此步骤Building the C# vSphere DLLs我在开发人员命令提示符中获得以下内容:
'pdf' => array(
'enabled' => true,
'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
'timeout' => 3600,
'options' => array(),
'env' => array(),
),
查看C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin>build.bat
1 file(s) copied.
Fixing HttpNfcLeaseInfo type, adding missing leaseState property
Generating VimService.cs
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.6.1055.0]
Copyright (c) Microsoft Corporation. All rights reserved.
Generating files...
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin\VimService.cs
Compiling original VimService.dll
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.6.1055.0]
Copyright (c) Microsoft Corporation. All rights reserved.
Generating XML serializers...
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin\VimServiceSerializers.cs
1 file(s) copied.
Optimizing VimService.cs by stripping serializer hint attributes.
Compiling optimized VimService.dll
FAILED
,看起来它在这一行上失败了:
build.bat
如果我手动运行echo Compiling optimized VimService.dll
csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs >nul || goto ERROR
,我会收到以下信息:
csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs
我也试过VS2017:
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin>csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs
Microsoft (R) Visual C# Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.
VimServiceSerializers.cs(32548,98): error CS8078: An expression is too long or complex to compile
要注意的行为,C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin>csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs
Microsoft (R) Visual C# Compiler version 2.0.0.61213
Copyright (C) Microsoft Corporation. All rights reserved.
VimServiceSerializers.cs(31372,109): error CS8078: An expression is too long or complex to compile
行和列每次都不同。
谷歌搜索错误CS8078,发现编译器耗尽堆栈空间是一个问题。 https://stackoverflow.com/a/8160109/6656422
如何成功编译VmWare的代码?
答案 0 :(得分:2)
我明白了。序列化程序CS文件具有长时间不间断的if ... else if ... else if ...
子句。编译器必须立即处理整个if / else表达式,这会导致它耗尽堆栈空间。
幸运的是,这些else if
中的每个分支都以return
语句终止。这使得所有else if
s在功能上等同于独立的if
语句,这些语句是独立解析的。
在多个地方进行此替换后,文件将进行编译。这是我修改过的VimServiceSerializers.cs:https://1drv.ms/u/s!Al6mzY0CpY7EnHqBRDyg-z0ctrjk
答案 1 :(得分:1)
将if ... else拆分为单独的if语句给出的答案是一种解决方案。另一个选择是检查用于编译代码的C#编译器的版本。我已经看到,与.NET 4.5、4.6捆绑在一起的csc.exe可以编译这样的代码而不会产生任何错误。但是Roslyn .NET编译器无法编译此类代码并生成CS8078错误。因此,如果您不想修改代码,另一个选择是更改C#编译器。例如下面的csc.exe可以编译这样的代码-
C:\Windows\Microsoft.NET\Framework\v4.0.30319>csc.exe /version
Microsoft (R) Visual C# Compiler version 4.6.1055.0
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.