C++ Docker中的Microsoft编译器

C++ Docker中的Microsoft编译器,c++,windows,visual-studio,docker,dockerfile,C++,Windows,Visual Studio,Docker,Dockerfile,我想设置一个DOCKER容器来支持完全基于C++编写的代码库的构建,生成的应用程序只在Windows上运行。 为此,我需要设置一个复制当前构建环境的容器来支持构建 我需要创建一个Dockerfile(如下所示)来构建这样的容器: 请考虑以下类型的伪代码DOCKFILE(忽略APT GET并考虑Windows中的任何其他工具来从命令行安装工具): 注意:我们的组织中有一个定制构建系统(不使用GNU Make)来执行构建。debug是提供给构建系统的目标,因为我想构建一个调试可执行文件 我的怀疑是:

我想设置一个DOCKER容器来支持完全基于C++编写的代码库的构建,生成的应用程序只在Windows上运行。 为此,我需要设置一个复制当前构建环境的容器来支持构建

我需要创建一个Dockerfile(如下所示)来构建这样的容器:

请考虑以下类型的伪代码DOCKFILE(忽略APT GET并考虑Windows中的任何其他工具来从命令行安装工具):

注意:我们的组织中有一个定制构建系统(不使用GNU Make)来执行构建。debug是提供给构建系统的目标,因为我想构建一个调试可执行文件

我的怀疑是:

  • 如何安装VisualStudio编译器(或在windows上运行的任何其他编译器)

  • 如何托管签名工具、压缩工具和其他可执行文件(在Docker Trusted Registry上);是否可以在DTR上托管可执行文件)

  • 我如何处理上述工具的许可(编译器、签名工具、压缩工具都需要许可才能运行)

  • 在我们的组织中,上述方法绝对有效。 但是安装机器的过程(安装和所有上述工具都需要花费大量的时间和精力)。 因此,我想创建一个Docker映像,它可以部署在一台裸机上,这样可以在更短的时间内完成整个构建环境的设置和运行

    这样做的一个更重要的目的是采用持续交付方法


    请提供相同的输入(尽量考虑所有的疑惑)。

    < P>。 我说的不是在Windows上的Hyper-V虚拟机上运行Linux(Alpine)主机:它不会运行任何Windows映像,只运行Linux映像


    我说的是Docker for Windows(提供您的支持)。直到最近,这只可能在一个上运行。

    我假设您已经可以运行Windows容器,例如docker run-it microsoft/windowsservercore

    < P> >我的<强> DOCKFrase<强>在Dox容器中使用VisualC++构建工具2015使用<强> CopoLaTye< /St>>:

    # escape=`
    
    FROM microsoft/windowsservercore
    
    # Install chocolatey
    RUN @powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1"
    
    # Install Visual C++ Build Tools, as per: https://chocolatey.org/packages/visualcpp-build-tools
    RUN choco install visualcpp-build-tools -version 14.0.25420.1 -y
    
    # Add msbuild to PATH
    RUN setx /M PATH "%PATH%;C:\Program Files (x86)\MSBuild\14.0\bin"
    
    # Test msbuild can be accessed without path
    RUN msbuild -version
    
    CMD [ "cmd.exe" ]
    
    使用Choco更简单,但下载本机web安装程序并在安静模式下运行,可以获得相同的结果,例如:

    visualcppbuildtools_full.exe /Q /L <LogFile> /Full
    
    VisualCPBuildTools\u full.exe/Q/L/full
    
    <>代码> 只回答你的第一点:这里有一个文档,我用它作为一个DOCKER图像的起点来编译一个Windows C++应用程序:

    我正在Windows Server 2016上运行Docker,并编译一个面向XP的遗留应用程序

    我最终的
    Dockerfile
    如下所示:

    # Use the latest Windows Server Core image.
    FROM microsoft/windowsservercore
    
    # Download the Visual Studio 2017 installer outside of the PATH.
    # This is required for Windows SDK 7.1A (XP targetting)
    ADD https://aka.ms/vs/15/release/vs_professional.exe C:\\TEMP\\vs_professional.exe
    
    # Add C:\Bin to PATH and install Build Tools with components we need
    RUN setx /m PATH "%PATH%;C:\Bin" \
    && C:\TEMP\vs_professional.exe --quiet --wait --norestart --nocache \
        --add Microsoft.VisualStudio.Component.Static.Analysis.Tools \
        --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
        --add Microsoft.VisualStudio.Component.VC.CMake.Project \
        --add Microsoft.VisualStudio.Component.VC.CoreBuildTools \
        --add Microsoft.VisualStudio.Component.VC.ATLMFC \
        --add Microsoft.VisualStudio.Component.VC.ATL \
        --add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop \
        --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP \
        --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP.Native \
        --add Microsoft.VisualStudio.Component.Windows10SDK \
        --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 \
        --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest \
        --add Microsoft.Component.VC.Runtime.UCRTSDK \
        --add Microsoft.VisualStudio.Component.WinXP \
    || IF "%ERRORLEVEL%"=="3010" EXIT 0
    
    # Start developer command prompt with any other commands specified.
    ENTRYPOINT "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" &&
    
    # Default to PowerShell if no other command specified.
    CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
    

    这太酷了!Visual C++ 2019有什么更新吗?
    # Use the latest Windows Server Core image.
    FROM microsoft/windowsservercore
    
    # Download the Visual Studio 2017 installer outside of the PATH.
    # This is required for Windows SDK 7.1A (XP targetting)
    ADD https://aka.ms/vs/15/release/vs_professional.exe C:\\TEMP\\vs_professional.exe
    
    # Add C:\Bin to PATH and install Build Tools with components we need
    RUN setx /m PATH "%PATH%;C:\Bin" \
    && C:\TEMP\vs_professional.exe --quiet --wait --norestart --nocache \
        --add Microsoft.VisualStudio.Component.Static.Analysis.Tools \
        --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
        --add Microsoft.VisualStudio.Component.VC.CMake.Project \
        --add Microsoft.VisualStudio.Component.VC.CoreBuildTools \
        --add Microsoft.VisualStudio.Component.VC.ATLMFC \
        --add Microsoft.VisualStudio.Component.VC.ATL \
        --add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop \
        --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP \
        --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP.Native \
        --add Microsoft.VisualStudio.Component.Windows10SDK \
        --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 \
        --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest \
        --add Microsoft.Component.VC.Runtime.UCRTSDK \
        --add Microsoft.VisualStudio.Component.WinXP \
    || IF "%ERRORLEVEL%"=="3010" EXIT 0
    
    # Start developer command prompt with any other commands specified.
    ENTRYPOINT "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" &&
    
    # Default to PowerShell if no other command specified.
    CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]