dockerfile shell instruction to run all further commands in ms build tools command prompt - c++

The instructions in the dockerfile:
SHELL ["C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Visual Studio 2022\\Visual Studio Tools\\VC\\x64 Native Tools Command Prompt for VS 2022.lnk"]
RUN cmake
gives me the error:
Step 5/6 : shell ["C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x64 Native Tools Command Prompt for VS 2022.lnk"]
---> Using cache
---> 6ae0c4b6e45e
Step 6/6 : RUN cmake
---> Running in 11bfaf29327d
container 11bfaf29327d2d636ef439569d53774f3c486d128b5d103c0d94523afa7a6f83 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: %1 is not a valid Win32 application. (0xc1)
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF7D032A41B: (caller: 00007FF7D02E5C9B) Exception(2) tid(390) 800700C1 %1 is not a valid Win32 application.
CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess]
Provider: 00000000-0000-0000-0000-000000000000]
The only workaround I have found is to use all the time:
RUN cd "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Auxiliary\\Build\\" \
&& vcvars64.bat \
&& cmake
but this is not very convenient.

Related

Docker image for building solution with both C++ and C# projects

I had a docker file that used to successfully build a VS2019 solution containing C++ and C# projects. Then recently it stopped working.
I've been investigating and trying various combinations of docker images, without success.
I've now got a test VS2019 solution with one C++ hello world console project and one C# .NET5 hello world console project. This does not compile using the following docker file:
e# escape=`
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
SHELL ["cmd", "/S", "/C"]
# Copy our Install script.
COPY Install.cmd C:\TEMP\
# Download collect.exe in case of an install failure.
ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe
ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\Temp\vs_buildtools.exe
ADD https://aka.ms/vs/16/release/channel C:\Temp\VisualStudio.chman
RUN C:\Temp\vs_buildtools.exe `
--quiet --wait --norestart --nocache `
--installPath C:\BuildTools `
--channelUri C:\Temp\VisualStudio.chman `
--installChannelUri C:\Temp\VisualStudio.chman `
--add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
--add Microsoft.Component.MSBuild `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
WORKDIR /src
ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] && CMD "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Commom7\Tools\VsDevCmd.bat"
The compiler error is
C:\src\dockertest\ConsoleApplications\ConsoleApplicationCpp\ConsoleApplicationCpp.vcxproj(28,3): error MSB4019: The imp
orted project "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.D
efault.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Vi
sual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.Default.props" is correct, and that the file exist
s on disk.
Interestingly, this installs MSBuild for VS2022, despite the aka.ms/vs/16 link requesting VS2019.
Interestingly, this installs .NET SDK 6.0.101, despite the FROM line asking for 4.8
But the main problem is the VC tools are not installed. The folder C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft does not contain the VC folder.
I've followed various examples but they don't appear to work any more with the recent docker images.
Try this:
# escape=`
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
SHELL ["cmd", "/S", "/C"]
ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\vs_buildtools.exe
RUN C:\vs_buildtools.exe `
--quiet --wait --norestart --nocache modify `
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
--add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools;includeRecommended `
--add Microsoft.VisualStudio.Workload.MSBuildTools;includeRecommended `
--add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
RUN del C:\vs_buildtools.exe
COPY . .
RUN nuget restore
RUN MSBuild GameClient.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64
WORKDIR /Product
ENTRYPOINT ["C:\\Product\\WOTS.exe", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

Visual C++ build tools seems to be installed But Bazel can't find the following tools: cl.exe, link.exe, lib.exe, ml64.exe

I am trying to build Angular on windows server 2019 AWS Virtual Machine.
I downloaded angular-master.zip from https://github.com/angular/angular
I unzipped this angular-master.zip
I downloaded following Prerequisite softwares.
1. Prerequisite Software
• Git and/or the GitHub app (for Mac or Windows); GitHub's Guide to Installing Git is a good source of information.
• Node.js, (version specified in the engines field of package.json) which is used to run a development web server, run tests, and generate distributable files.
• Yarn (version specified in the engines field of package.json) which is used to install dependencies.
• Java Development Kit which is used to execute the selenium standalone server for e2e testing.
I have done - yarn install
I have done - yarn global add windows-build-tools. It has installed C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools on my Virtual machine. It has also installed - C:\Users\Administrator.windows-build-tools\python27
I have done - node ./scripts/build/build-packages-dist.js
it is giving following error –
INFO: Analyzed 18 targets (1 packages loaded, 179 targets configured).
INFO: Found 18 targets...
ERROR: C:/users/administrator/_bazel_administrator/e2kq7fn3/external/com_google_protobuf/BUILD:267:11: C++ compilation of rule '#com_google_protobuf//:protoc_lib' failed (Exit 1)
The target you are compiling requires Visual C++ build tools.
Bazel couldn't find a valid Visual C++ build tools installation on your machine.
Visual C++ build tools seems to be installed at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC
But Bazel can't find the following tools:
cl.exe, link.exe, lib.exe, ml64.exe
Please check your installation following https://docs.bazel.build/versions/master/windows.html#using
INFO: Elapsed time: 2210.447s, Critical Path: 1095.73s
INFO: 18 processes: 16 local, 2 worker.
FAILED: Build did NOT complete successfully
child_process.js:669
throw err;
^
Error: Command failed: yarn --cwd "c:\angular\angular-master" --silent bazel build --config=release --config=view-engine //packages/upgrade:npm_package //packages/service-worker:npm_package //packages/router:npm_package //packages/platform-webworker-dynamic:npm_package //packages/platform-webworker:npm_package //packages/platform-server:npm_package //packages/platform-browser-dynamic:npm_package //packages/platform-browser:npm_package //packages/localize:npm_package //packages/language-service:npm_package //packages/forms:npm_package //packages/elements:npm_package //packages/core:npm_package //packages/compiler-cli:npm_package //packages/compiler:npm_package //packages/common:npm_package //packages/bazel:npm_package //packages/animations:npm_package
at checkExecSyncError (child_process.js:630:11)
at execSync (child_process.js:666:15)
at exec (c:\angular\angular-master\scripts\build\package-builder.js:122:18)
at buildTargetPackages (c:\angular\angular-master\scripts\build\package-builder.js:81:3)
at Object.<anonymous> (c:\angular\angular-master\scripts\build\build-packages-dist.js:18:1)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
status: 1,
signal: null,
output: [ null, null, null ],
pid: 6708,
stdout: null,
stderr: null
}

docker build failed : Not able to set the environment variables

I am trying to build a QT application using docker. I have visual studio 2015 build tools and QT 5.11.2 as base docker image. When I try to docker build QT application, I get this error.
C:\Qt\5.11.2\msvc2015_64\include\QtCore/qglobal.h(45): fatal error
C1083: Cannot open include file: 'type_traits': No such file or
directory
When I checked for this file 'type_traits', inside docker it exists inside this path:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
The docker build fails at this step:
RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe
This command RUN ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat", "x86_amd64"] sets up the environment variables, How to verify that these still exist for the rest of the RUN commands in dockerfile?
Below is my docker file:
#My base docker image containing QT5.11.2 and Visual build tools 2015
FROM qt
COPY ["./", "C:/app"]
RUN $env:PATH ='C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin;' + $env:PATH;\
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);
RUN $env:PATH ='C:\Qt\5.11.2\msvc2015_64\bin;' + $env:PATH;\
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);
RUN $env:PATH ='C:\Qt\Tools\QtCreator\bin\jom.exe;' + $env:PATH;\
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);
RUN $env:PATH ='C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include;' + $env:PATH;\
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);
WORKDIR C:\\app
RUN ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat", "x86_amd64"]
RUN qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"
RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe qmake_all
RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe
RUN C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe install
RUN mkdir dist\debug_build\app_dist
RUN xcopy app_dist\dist_redist\*.* dist\debug_build\app_dist /E /Y >NUL
CMD cmd
How to verify that these still exist for the rest of the RUN commands in dockerfile?
They won't.
In the environment that exists here
RUN ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat", "x86_amd64"]
executes a process that executes the batch file with argument x86_amd64, creating new environment
settings for any child processes - of which there are none - then exits. Then:
RUN qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"
executes another process in the environment that existed there, which is still
the environment. And so on.
There's nothing specific to Docker, or Windows, about this behaviour. In any operating
system, a process cannot modify the environment of its parent, only the copy of
that environment that it inherits and passes to any child processes.
If you want all of the commands:
qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe qmake_all
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe install
to start in an environment modified by vcvarsall.bat x86_amd64, then you
have run all of them in the same shell as that command, e.g.
RUN "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat" x86_amd64 && ^
qmake app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug" && \
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe qmake_all && \
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe && \
C:\\Qt\\Tools\\QtCreator\\bin\\jom.exe install
See also the dockerfile ENV command
for a way of making global environment settings in a docker container.

How to accept android licenses after installing Tools for Cordova using Visual Studio 2017

I installed Visual Studio 2017 with the "Mobile development with JavaScript" option and "Android SDK setup" selected.
When I check Tools->Options->Tools for Apache Cordova->Environment Variable Overrides I can see that ANDROID_HOME has been set to "C:\ProgramData\Microsoft\AndroidSDK\25"
When I try to build my project I get an error:
cordova-build error : > You have not accepted the license agreements
of the following SDK components: cordova-build error : [Android SDK
Platform 25].
I open a Windows command prompt and go to the directory containing the sdkmanager:
cd C:\ProgramData\Microsoft\AndroidSDK\25\tools\bin
I try sdkmanager --licenses but that results in
Error: Unknown argument --licenses
So I try sdkmanager --update and that results in
Warning: An error occurred during installation: Failed to move away or
delete existing target file:
C:\ProgramData\Microsoft\AndroidSDK\25\tools Move it away manually and
try again.
So I move up to the folder above the tools folder and rename it:
ren tools tools.old
then try the update again:
tools.old\bin\sdkmanager --update
this gave me a warning:
Warning: Observed package id 'tools' in inconsistent location
'C:\ProgramData\Microsoft\AndroidSDK\25\tools.old' (Expected
'C:\ProgramData\Microsoft\AndroidSDK\25\tools')
But after a lengthy wait the command reported that it was done and I could see that there was a new "tools" folder.
I tried to build my project again. Now my error is:
Could not find gradle wrapper within Android SDK. Might need to update
your Android SDK.
Looked here:
C:\ProgramData\Microsoft\AndroidSDK\25\tools\templates\gradle\wrapper
References:
https://stackoverflow.com/a/47305199/150342
https://developer.android.com/studio/command-line/sdkmanager.html
You have not accepted the license agreements of the following SDK components

Windows container fails to build VS 2013 C++ project with error MSB6006: “midl.exe” exited with code -2147024774

I should be able to build a C++ project on a windows docker container using MSBuild.exe
Command:
C:\'Program Files (x86)'\MSBuild\12.0\Bin\MSBuild.exe .\TestNative.sln /p:Configuration=Release /p:Platform=x64 /m /t:Build /p:ResGenExecuteAsTool=true /toolsversion:12.0
C++ Project fails to build with error:
Midl:
C:\Program Files (x86)\Windows Kits\8.1\bin\x86\midl.exe /W1 /nologo /char signed /env x64 /h “Enumglob.h” /tlb “x64\ReleaseMinDependency\TestNativeCore.tlb” Enumglob.idl
64 bit Processing .\Enumglob.idl
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(1178,5): error MSB6006: “midl.exe” exited with code -2147024774.
....
....
Build FAILED.
Information
This is my Dockerfile which already has the Visual C++ Redistributables installed and the project copied over using Docker cp command. I’m not sure what else is missing and the error message is not helpful.
FROM chemsorly/msbuilder:1.0.0-vsc
SHELL ["powershell"]
# Download VC++ 2010 SP1 Redistributable Package (x64)
RUN Invoke-WebRequest http://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe -OutFile "$env:TEMP\vc2010x64.exe" -UseBasicParsing
RUN Start-Process "$env:TEMP\vc2010x64.exe" '/features + /q' -wait
RUN Remove-Item "$env:TEMP\vc2010x64.exe"
# Download VC++ 2012 Update 4 Redistributable Package (x64)
RUN Invoke-WebRequest http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe -OutFile "$env:TEMP\vc2012x64.exe" -UseBasicParsing
RUN Start-Process "$env:TEMP\vc2012x64.exe" '/features + /q' -wait
RUN Remove-Item "$env:TEMP\vc2012x64.exe"
# Download VC++ 2013 Redistributable Package (x64)
RUN Invoke-WebRequest http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe -OutFile "$env:TEMP\vc2013x64.exe" -UseBasicParsing
RUN Start-Process "$env:TEMP\vc2013x64.exe" '/features + /q' -wait
RUN Remove-Item "$env:TEMP\vc2013x64.exe"
# Note: Add MSBuild to path
RUN setx PATH '%PATH%;C:\\Program Files (x86)\\MSBuild\\14.0\\Bin'
# Download VC++ 2015 Build Tools
RUN Invoke-WebRequest 'http://go.microsoft.com/fwlink/?LinkId=691126"&"fixForIE=.exe"&"__hstc=268264337.f43737e851d862336312053b3a368915.1511781465043.1511781465043.1511781465043.1"&"__hssc=268264337.1.1511781465043"&"__hsfp=1781426681' -OutFile "$env:TEMP\vc++2015bt.exe" -UseBasicParsing
RUN Start-Process "$env:TEMP\vc++2015bt.exe" '/features + /q' -wait
Question: I'm not sure what tools I'm missing on my container so what is the above error and how can I resolve it?