我正在使用 Azure DevOps for CI 开发一个带有 Android 目标的 Xamarin Forms 项目。我的项目在我的本地机器和 Azure Pipeline 中构建良好。现在,我想用 DocFx 生成代码文档。因此,我配置了一个 powershell 脚本来下载 docfx.console 工具并从我的 docfx.json 文件中执行它。该脚本在我的本地机器上运行良好,并且文档已正确生成。
我在 Azure Pipeline 中添加了一个任务来执行我的 powershell 脚本,并且 DocFx 失败并出现 FileNotFoundException 异常,该异常涉及 System.Buffers.dll 文件和以下日志:
[21-04-15 08:30:17.934]Info:[MetadataCommand.ExtractMetadata]Loading projects...
[21-04-15 08:30:29.096]Warning:[MetadataCommand.ExtractMetadata](D:/Path/MyProject.Android/MyProject.Android.csproj)Workspace failed with: [Failure] Msbuild failed when processing the file 'D:/Path/MyProject.Android/MyProject.Android.csproj' with message: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.EmbeddedResource.targets: (36, 5): System.IO.FileNotFoundException: Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at Xamarin.Tools.Zip.ZipArchive.stream_callback(IntPtr state, IntPtr data, UInt64 len, SourceCommand cmd)
at Xamarin.Tools.Zip.Native.zip_source_function_create(zip_source_callback callback, IntPtr user_data, zip_error_t& errorp)
at Xamarin.Tools.Zip.ZipArchive..ctor(Stream stream, IPlatformOptions options, OpenFlags flags) in /Users/runner/work/1/s/ZipArchive.cs:line 91
at Xamarin.Tools.Zip.ZipArchive.CreateInstanceFromStream(Stream stream, OpenFlags flags, IPlatformOptions options) in /Users/runner/work/1/s/ZipArchive.Unix.cs:line 24
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(IDictionary`2 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments)
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.RunTask()
at Xamarin.Android.Tasks.AndroidTask.Execute()
我尝试在不进行更改的情况下在 .csproj 文件旁边添加以下 app.config 文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1"/>
<bindingRedirect oldVersion="4.0.2.0-4.0.3.0" newVersion="4.0.3.0" xmlns="urn:schemas-microsoft-com:asm.v1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
信息:
DocFx 版本:2.57.2
Xamarin 表单版本:5.0.0.2012
Azure Pipeline 构建代理:Microsoft 托管的“最新窗口”