错误消息
ODT(Office 部署工具)日志在安装到 Windows 容器(服务器核心)时报告错误:C2R 客户端返回失败错误代码,错误代码:17002
环境
- 安装了桌面体验的 Windows Server 2019 (1809) 中的行为。
- ODT 安装结果:成功。
- test-o365.ps1:成功。
- 容器中的行为 (mcr.microsoft.com/windows/servercore:ltsc2019)
- ODT 安装结果:否定(C2R 客户端返回失败错误代码,错误代码:17002)
- test-o365.ps1:否定:HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)
Dockerfile
FROM mcr.microsoft.com/windows/servercore:ltsc2019
WORKDIR C:/setup
COPY . .
ENTRYPOINT startup.cmd
startup.cmd
curl.exe https://download.microsoft.com/download/2/7/A/27AF1BE6-DD20-4CB4-B154-EBAB8A7D4A7E/officedeploymenttool_12325-20288.exe --output .\
officedeploymenttool_12325-20288.exe
officedeploymenttool_12325-20288.exe /quiet /passive /extract:.
setup.exe /configure o365.xml
powershell -file test-o365.ps1
pause
o365.xml
<Configuration>
<Add OfficeClientEdition="64" Channel="Monthly">
<Product ID="O365ProPlusRetail">
<Language ID="en-us" />
</Product>
</Add>
<!-- <Updates Enabled="TRUE" Channel="Monthly" /> -->
<Display Level="None" AcceptEULA="TRUE" />
<Logging Level="Standard" Path="." />
<!-- <Property Name="AUTOACTIVATE" Value="1" /> -->
</Configuration>
测试-o365.ps1
# Write current datetime into result.xlsx to verify that Office COM component is working.
$filename = [System.Environment]::CurrentDirectory + "\result.xlsx"
$filename
if ([System.IO.File]::Exists($filename )) {
Remove-Item $filename
}
$xl=New-Object -ComObject Excel.Application
$xl.Visible=$false
$wb=$xl.WorkBooks.Add()
$ws=$wb.WorkSheets.item(1)
$ws.Cells.Item(1,1)= [System.DateTime]::Now
$wb.SaveAs($filename)
$xl.Quit()
更多信息
我们已经意识到文章 [3] 中提到的“服务器端 Office 自动化”问题。目前阶段,我们正在评估在 Windows 容器中运行旧版 ASP.NET 应用程序并启用 Office/COM 互操作的可能性。
引用文献
最佳答案
我已经为此苦苦挣扎了一段时间,终于成功了。我发现 17002 错误的解决方案是在交互式运行 docker 镜像时运行 setup.exe/configure config.xml,然后提交该容器。这对我在 windows:1809 图像上有用。
完整文章
我将下载的 Office 文件单独复制到 docker 镜像中,因为我在从 docker 文件内部下载文件时遇到问题 (see here) 。因此,我将文件夹 Office
与 docker 文件位于同一级别,其中包含 setup.exe/download config.xml
的内容。然后下面的 docker 文件构建了一个基础镜像。我运行了 docker run -it {IMAGEID} powershell ,导航到 C:\\odtsetup 并使用交互式控制台运行 setup.exe/configure config.xml ,退出容器并运行
docker stop {CONTAINERID}
docker commit {CONTAINERID}`
我现在有一个安装了 docker 的基本 Windows 服务器镜像,并且可以在我的应用程序的 dockerfile 中使用它。如果我需要更新服务器镜像或 Excel 版本,我需要再次手动执行此操作,但我很庆幸它能正常工作。
DOCKERFILE
FROM mcr.microsoft.com/windows:1809
WORKDIR C:\\odtsetup
ADD https://download.microsoft.com/download/2/7/A/27AF1BE6-DD20-4CB4-B154-EBAB8A7D4A7E/officedeploymenttool_13426-20308.exe odtsetup.exe
RUN odtsetup.exe /quiet /norestart /extract:C:\\odtsetup
ADD config.xml .
ADD Office Office\\
config.xml
<Configuration>
<Add OfficeClientEdition="64" Channel="PerpetualVL2019">
<Product ID="O365ProPlusRetail">
<Language ID="MatchOS" />
<ExcludeApp ID="Access" />
<ExcludeApp ID="Groove" />
<ExcludeApp ID="Lync" />
<ExcludeApp ID="OneDrive" />
<ExcludeApp ID="OneNote" />
<ExcludeApp ID="Outlook" />
<ExcludeApp ID="PowerPoint" />
<ExcludeApp ID="Publisher" />
<ExcludeApp ID="Teams" />
<ExcludeApp ID="Word" />
</Product>
</Add>
<Updates Enabled="FALSE" />
<Display Level="None" AcceptEULA="TRUE" />
<Property Name="AUTOACTIVATE" Value="1"/>
<Property Name="FORCEAPPSHUTDOWN" Value="TRUE" />
<Remove All="TRUE">
</Remove>
</Configuration>
关于.net - 将 Office 安装到 Windows 容器中(servercore :ltsc2019) failed with error code 17002,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60949149/