要找出原因,请执行以下操作:
- 转到工具/选项/项目和解决方案/构建和运行。
- 将 MSBuild 项目构建输出详细程度至少设置为“详细”。
- 构建您的项目。
- 转到输出窗口并在“显示输出”中选择“构建”。
- 搜索“SGEN.EXE”。这样你就会找到导致错误的命令行,比如这个:
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\sgen.exe /assembly:C:\MySolutionFolder\Bin\x64\MyAssembly.dll /reference:"C:\Users\MyWindowsUser.nuget\packages\system.runtime.windowsruntime\4.6.0\buildTransitive\net461\..\..\ref\netstandard2.0\System.Runtime.WindowsRuntime.dll,C:\Users\MyWindowsUser.nuget\packages\system.runtime.windowsruntime.ui.xaml\4.6.0\build\net461\..\..\ref\netstandard2.0\System.Runtime.WindowsRuntime.UI.Xaml.dll,C:\Users\MyWindowsUser.nuget\packages\microsoft.toolkit.forms.ui.controls.webview\6.0.0\lib\net462\Microsoft.Toolkit.Forms.UI.Controls.WebView.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\mscorlib.dll,C:\Users\MyWindowsUser.nuget\packages\newtonsoft.json\6.0.1\lib\net45\Newtonsoft.Json.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\PresentationCore.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.ComponentModel.DataAnnotations.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Core.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Data.DataSetExtensions.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Data.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Data.Linq.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Design.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Device.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Drawing.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Runtime.Remoting.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Facades\System.ValueTuple.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Windows.Forms.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Xaml.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Xml.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\UIAutomationClient.dll,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.AI.MachineLearning.MachineLearningContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.AI.MachineLearning.Preview.MachineLearningPreviewContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.ApplicationModel.Activation.ActivatedEventsContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.ApplicationModel.Activation.ActivationCameraSettingsContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.ApplicationModel.Activation.ContactActivatedEventsContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.ApplicationModel.Activation.WebUISearchActivatedEventsContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.ApplicationModel.Background.BackgroundAlarmApplicationContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.ApplicationModel.Calls.Background.CallsBackgroundContract.winmd,C:\Users\MyWindowsUser.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.ApplicationModel.Calls.CallsPhoneContract.winmd," /compiler:/keycontainer:VS_KEY_0011223344556677 /compiler:/platform:AnyCPU
为简洁起见,我将其缩短了。如您所见,有很多参考资料。由于它们每个都使用完整路径,因此语句的总长度很可能超过最大命令行长度,似乎是 32,000:
1>C:\MySolutionFolder\MyProject.csproj(1806,5): warning MSB6002: The command-line for the "SGen" task is too long. Command-lines longer than 32000 characters are likely to fail. Try reducing the length of the command-line by breaking down the call to "SGen" into multiple calls with fewer parameters per call.
1>C:\SBCZ\Br\IS-13869_MWV_P\w1\Source\ITML.SC.Global\ITML.SC.Global.Resources\ITML.SC.Global.Resources\ITML.SC.Global.Resources.csproj(1806,5): error MSB6003: The specified task executable "sgen.exe" could not be run. System.ComponentModel.Win32Exception (0x80004005): The filename or extension is too long
我不确定如何将此调用拆分为多个调用。