“sgen.exe”无法在 Azure Pipelines 上的 VSBuild 中运行

998*_*823 10 msbuild sgen azure azure-devops azure-pipelines

在本地运行构建很好,没有任何问题。当我在 Azure Pipeline 上运行它时,它出错了。

详细的错误信息是

“SGen”任务的命令行太长。超过 32000 个字符的命令行可能会失败。尝试通过将对“SGen”的调用分解为多个调用来减少命令行的长度,每个调用的参数较少。[D:\a\1\s\eFetch.Web.Core\eFetch.Web.Core.csproj]

##[错误]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3645,5):错误 MSB6003:指定的任务可执行文件“sgen” .exe”无法运行。System.ComponentModel.Win32Exception(0x80004005):文件名或扩展名太长

在此输入图像描述

Azure Pipeline 上的 VSBuild

- task: VSBuild@1
  inputs:
    solution: '$(agent.builddirectory)\s$(Project1-Folder)$(Project1-Name).csproj'
    msbuildArgs: '/p:OutputPath="$(build.binariesDirectory)$(Project1-Folder)\bin" /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactStagingDirectory)$(Project1-Name)TempFolder"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)

我们做了一些研究。通常出现的是将GenerateSerializationAssemblies设置为AutoOff。我们的项目已经处于“自动”状态,因此我们将其设置为“关闭”,但错误仍然存​​在。

有没有办法绕过某些 dll 引用的长路径?就像下面这样

  • 参考:“C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.7.2 \ System.Xml.Linq.dll”
  • /reference:“C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\Facades\System.Xml.ReaderWriter.dll”

另一种情况是多次调用 sgen.exe,但我们不确定如何执行此操作,因为 sgen.exe 是在 VSBuild / msbuild.exe 内部调用的。

理想情况下,我们希望不必关闭GenerateXmlSerialization,而是让它正常工作。