在Windows 10上运行VS 2017 15.5.3。
获取此一般错误“指定的任务可执行文件”sgen.exe“无法运行。文件名或扩展名太长” 在Release配置和X64平台中构建项目时。 但它在Debug配置和Any CPU平台上构建良好。
中所述能够在将“生成序列化组件”设置为OFF后进行构建。
不要认为文件名很长。 有人会对此有所了解吗?
最诚挚的问候,
Damodar
答案 0 :(得分:9)
MSB6003无法运行指定的任务可执行文件“sgen.exe”。文件名或扩展名太长
我们知道,sgen.exe用于为指定程序集中的类型创建XML序列化程序集,以便在序列化或反序列化指定类型的对象时提高XmlSerializer的启动性能。
如果您不需要XML序列化程序集,则应将GenerateSerializationAssemblies
的属性设置为Auto
或off
。并且默认仅为代理类型生成“任何CPU”。这就是为什么你在Release配置和X64平台上得到错误而在Debug配置和Any CPU平台上没有错误的原因。您可以右键单击项目 - > Properties |> Build-> GenerateSerializationAssemblies,将值设置为off。然后卸载项目,编辑项目,在项目文件中,您可以找到以下代码行:
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
但是,这行代码存在于条件Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
上,因此,要解决此问题,您可以手动将此行代码添加到其他条件。您的项目文件配置最终会看起来像这样:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
...
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
...
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
有关详细信息,请参阅Generating an Xml Serialization assembly as part of my build。
希望这有帮助。
答案 1 :(得分:4)
答案 2 :(得分:2)
要找出原因,请执行以下操作:
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
我不确定如何将此呼叫拆分为多个呼叫。