Simas Paškauskas
Simas Paškauskas

Reputation: 623

vs_buildtools.exe does not install actually install Build Tools 2022 on docker if you use Microsoft.VisualStudio.Workload.XamarinBuildTools

I've been trying to setup docker environment for .net MAUI continues development (Jenkins) and it seems, that installation of .Maui workload makes the VS_build Tools not to install at all. After failing to get it running for a few weeks now with different levels of success - I took the example from the docs and added --add Microsoft.VisualStudio.Workload.XamarinBuildTools. If I run without it - all is fine. "2022" dir is in C:\Program Files (x86)\Microsoft Visual Studio everything seems fine. But - if I add Workload.XamarinBuildTools - that dir does not contain 2022. Seems that the installation fails for some reason.

Things I've tried:

Ideas:

dockerfile

# escape=`

# Use the latest Windows Server Core 2019 image.
FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

USER ContainerAdministrator

RUN `
    # Download the Build Tools bootstrapper.
    curl -SL --output vs_buildtools.exe https://aka.ms/vs/17/release/vs_buildtools.exe `
    `
    # Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
    && (start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
        --add Microsoft.VisualStudio.Workload.AzureBuildTools `
        --add Microsoft.VisualStudio.Workload.XamarinBuildTools `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
        --remove Microsoft.VisualStudio.Component.Windows81SDK `
        || IF "%ERRORLEVEL%"=="3010" EXIT 0) `
    `
    # Cleanup
    && del /q vs_buildtools.exe

# Define the entry point for the docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
# ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

RUN mkdir c:\working

WORKDIR C:\working

Any ideas or help would be highly appreciated.

[EDIT] Have been testing multiple scenarios and I found one that seems to be workeing. Installing every component in workload instead of workload seems to do the trick

# escape=`

# Use the latest Windows Server Core 2019 image.
FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

USER ContainerAdministrator

RUN `
    # Download the Build Tools bootstrapper.
    curl -SL --output vs_buildtools.exe https://download.visualstudio.microsoft.com/download/pr/5c9aef4f-a79b-4b72-b379-14273860b285/bd2dd3a59d2553382f89712d19e4d5c3d930d9a41c9426cf8194dd5a3a75875f/vs_BuildTools.exe `
    `
    # Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
    && start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
        --add android `
        --add Component.Android.SDK.MAUI `
        --add Component.OpenJDK `
        --add ios `
        --add maccatalyst `
        --add maui.android `
        --add maui.blazor `
        --add maui.core `
        --add maui.ios `
        --add maui.maccatalyst `
        --add maui.windows `
        --add Microsoft.Component.MSBuild `
        --add Microsoft.Component.NetFX.Native `
        --add Microsoft.Net.Component.4.6.1.TargetingPack `
        --add Microsoft.Net.Component.4.8.SDK `
        --add microsoft.net.runtime.android `
        --add microsoft.net.runtime.android.aot `
        --add microsoft.net.runtime.android.aot.net6 `
        --add microsoft.net.runtime.android.net6 `
        --add microsoft.net.runtime.ios `
        --add microsoft.net.runtime.ios.net6 `
        --add microsoft.net.runtime.maccatalyst `
        --add microsoft.net.runtime.maccatalyst.net6 `
        --add microsoft.net.runtime.mono.tooling `
        --add microsoft.net.runtime.mono.tooling.net6 `
        --add Microsoft.NetCore.Component.Runtime.6.0 `
        --add Microsoft.NetCore.Component.Runtime.7.0 `
        --add Microsoft.NetCore.Component.SDK `
        --add Microsoft.VisualStudio.Component.NuGet.BuildTools `
        --add Microsoft.VisualStudio.Component.Roslyn.Compiler `
        --add Microsoft.VisualStudio.ComponentGroup.UWP.BuildTools `
        --add runtimes.ios `
        --add runtimes.ios.net6 `
        --add runtimes.maccatalyst `
        --add runtimes.maccatalyst.net6 `
       
    # Cleanup
    && del /q vs_buildtools.exe

# Define the entry point for the docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
# ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

RUN mkdir c:\working

WORKDIR C:\working

Upvotes: 5

Views: 3250

Answers (1)

Javi Carnero
Javi Carnero

Reputation: 467

Ok so in my case the issue was that docker is configured by default to use layers of a maximum of 20GB, while when installing workloads VS usually needs more than that.

I recommend doing two things to fix it:

  1. Remove all images & containers from docker desktop, docker rm $(docker ps -aq) && docker image prune -a, then add "storage-opts": ["size=127GB"] to docker daemon json file (settings -> Docker Engine) or at ($env:USERPROFILE/.docker/windows-daemon.json). Lastly restart computer (restart docker desktop only may not be enough).

  2. Finally, modify slightly your install script, so you can output the errors if there is any, and build again. Example:

# escape=`

# https://learn.microsoft.com/en-us/visualstudio/install/build-tools-container?view=vs-2022
# Use the latest Windows Server Core image with .NET Framework 4.8
# This is better than servercore this image already has installed VS with .Net framework and other utils
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2022

WORKDIR /azp

########################################################################################
# Setup visual studio workloads

# https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2022
RUN `
    # Install VS Build Tools
    curl -fSLo vs_BuildTools.exe https://aka.ms/vs/17/release/vs_BuildTools.exe `
    && start /w vs_BuildTools modify ^ `
    --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" ^ `
    --add Microsoft.VisualStudio.Workload.AzureBuildTools ^ `
    --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools ^ `
    --add Microsoft.VisualStudio.Workload.UniversalBuildTools ^ `
    --add Microsoft.VisualStudio.Workload.XamarinBuildTools ^ `
    --add Microsoft.VisualStudio.Component.Windows10SDK.18362 ^ `
    --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 ^ `
    --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 ^ `
    --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 ^ `
    --remove Microsoft.VisualStudio.Component.Windows81SDK ^ `
    --quiet --norestart --nocache --wait `
    && powershell -Command "if ($err = dir $Env:TEMP -Filter dd_setup_*_errors.log | where Length -gt 0 | Get-Content) { throw $err }" `
    && del vs_BuildTools.exe

RUN `
    # Cleanup
    (for /D %i in ("%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\*") do rmdir /S /Q "%i") `
    && (for %i in ("%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\*") do if not "%~nxi" == "vswhere.exe" del "%~i") `
    && powershell Remove-Item -Force -Recurse "%TEMP%\*" `
    && rmdir /S /Q "%ProgramData%\Package Cache"

Upvotes: 2

Related Questions