在 Azure DevOps 管道中使用命令行任务通过执行 EXE 尝试打开 excel 文件时出现异常

Getting exception while trying to open excel file by executing an EXE using command-line task in Azure DevOps Pipeline

我正在尝试通过在 DevOps 管道中使用命令行任务传递一些参数来执行 exe。该 exe 用于使用 Microsoft.Office.Interop.Excel 读取 excel 文件。

管道配置为使用自托管代理。 Office 安装在代理机器上,exe 在那里工作正常。试图在代理计算机上执行命令行任务中使用的相同命令,并且其工作无一例外。

代理计算机上的代理服务配置为 运行 作为服务并使用管理员帐户。

运行构建时,在命令行任务中记录了以下异常,

    Unhandled Exception: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC
   at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
   at Xerox.DM.SQLIntegration.ExcelHelper.GetExcelWorksheet_v1(String fileName, String sheetName, Application excelApp, Workbook workbook)
   at Xerox.DM.SQLIntegration.ExcelToSql.GenerateInsertSqlCode(String fileName, String sheetName, Application excelApp)
   at Xerox.DM.SQLIntegration.SimpleLogic.RunSilentMode(String[] args)
   at Xerox.DM.SQLIntegration.Program.Main(String[] args)

同一用户帐户(管理员帐户)用于代理服务和 RDP 连接。命令通过 RDP 成功执行,但在 运行ning 构建时抛出异常。应该是什么原因?

我找到了这个问题的解决方案。这是一个访问权限问题。即使我在管理员帐户下将构建代理配置为 运行,也会使用此用户帐户创建一个单独的用户组

并且该组没有访问 Microsoft Excel 应用程序组件服务的权限。如下图所示设置权限将解决此问题。