是否可以在Windows Server的Windows容器中安装任何版本的Visual Studio?
动机是使用Windows容器构建连续集成系统中的软件,以便构建环境得到标准化。
是否可以在Windows Server的Windows容器中安装任何版本的Visual Studio?
动机是使用Windows容器构建连续集成系统中的软件,以便构建环境得到标准化。
Visual Studio 在 Core Server 上似乎没有官方支持, 但我同意能够这样做会非常好。让我们尝试:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell"]
RUN Invoke-WebRequest "https://aka.ms/vs/16/release/vs_community.exe" -OutFile "$env:TEMP\vs_community.exe" -UseBasicParsing
RUN & "$env:TEMP\vs_community.exe" --add Microsoft.VisualStudio.Workload.NetWeb --quiet --wait --norestart --noUpdateInstaller | Out-Default
RUN & 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe' /version
CMD ["powershell"]
我正在将这个图像推送到 lukaslansky/visualstudio-netwebworkload,请谨慎使用。
构建的输出结果为:
[...]
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
看起来这个方法可行!您应该尝试使用那些--add
安装程序参数来准确指定构建所需的组件,它们对应于GUI中看到的工作负载和组件。请参阅文档。
FROM microsoft/windowsservercore
RUN powershell.exe -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SETX PATH "%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
RUN choco install -y visualstudio2017buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --installPath C:\BuildTools" || IF "%ERRORLEVEL%"=="3010" EXIT 0
RUN call "C:\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
最近我花了很多时间研究这个问题,因为我们的目标是建立“dockerized” DevOps代理程序,能够运行VsBuild@1
管道任务(以及其他任务)。
一般来说,如果你不需要VsBuild@1
(或者其他与Visual Studio相关的任务,比如VsTest@2
等),那么最好使用https://hub.docker.com/_/microsoft-dotnet-framework-sdk/作为基础镜像,然后就可以愉快地工作了;这些镜像已经安装了构建工具和VS测试代理。
但是,安装VS也是可能的。以下是一些注意事项:
%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen update
来手动触发它们。请注意,在Docker中安装VS会以各种方式导致其失败,因此您需要找到解决方法。DockerFile
以获取一些参考;特别有趣的是.NET Framework targeting packs的手动安装:https://github.com/microsoft/dotnet-framework-docker/blob/main/src/sdk/4.8.1/windowsservercore-ltsc2022/Dockerfile
(如果此链接因文件移动而停止工作,则值得查看https://github.com/microsoft/dotnet-framework-docker存储库中的DockerFile
)--add
参数安装的VS组件ID列表。