Visual C++ Redistributable Command Line Install

1 view
Skip to first unread message

Ling Kliment

unread,
Aug 4, 2024, 1:14:41 PM8/4/24
to specheadtiho
Youmay think that unless you explicitly use some external library (like FMOD), your program will not require any additional libraries to work, but when coding in C++ using Visual Studio, this is not the case. The functions of standard C/C++ library are implemented in a package of DLL-s called Microsoft Visual C++ Redistributable Package. Each version of Visual Studio has their own set. For example, version for Visual Studio 2013 (Release configuration) consists of files: msvcr120.dll, msvcp120.dll.

You can make your application not requiring this library by setting your project options in Configuration Properties > C/C++ > Code Generation > Runtime Library to "Multi-threaded [Debug]" without the "DLL" part, which makes it statically linked. Alternatively, you can distribute these DLL files (although I'm not sure if this is legal) or the whole library installer together with your application. The library is small and free, available to download from Microsoft website:


The question is: can you launch the installer of these packages with some special parameter so the user doesn't have to go through all the setup wizard, confirming each step? The answer is yes, but as Microsoft likes to change everything very often :) the exact command line is different depending on version. Here is the whole set:


If you would like to install it in unattended mode (which will show a small progress bar but not require any user interaction), you can change the "/qn" switch above to "/qb". Unattended mode + disabled "Cancel" button is "/qb!".


To quickly install all of these libraries on the machines where lots of different applications are launched that may require them, I gathered all the libraries in one directory and I have written following BAT script:


When you deploy an application, you must also deploy the files that are required to support it. If any of these files are provided by Microsoft, check whether you're permitted to redistribute them. You'll find a link to the Visual Studio license terms in the IDE. Use the License terms link in the About Microsoft Visual Studio dialog box. Or, download the relevant EULAs and licenses from the Visual Studio License Directory.


To view the "REDIST list" that's referenced in the "Distributable Code" section of the Visual Studio 2022 Microsoft Software License Terms, see Distributable code files for Microsoft Visual Studio 2022


To view the "REDIST list" that's referenced in the "Distributable Code" section of the Visual Studio 2019 Microsoft Software License Terms, see Distributable Code Files for Microsoft Visual Studio 2019


To view the "REDIST list" that's referenced in the "Distributable Code" section of the Visual Studio 2017 Microsoft Software License Terms, see Distributable Code Files for Microsoft Visual Studio 2017.


To view the "REDIST list" that's referenced in the "Distributable Code" section of the Visual Studio 2015 Microsoft Software License Terms, see Distributable Code Files for Microsoft Visual Studio 2015.


The easiest way to locate the redistributable files is by using environment variables set in a developer command prompt. In Visual Studio 2022, the redistributable files are in the %VCINSTALLDIR%Redist\MSVC\v143 folder. In the latest version of Visual Studio 2019, you'll find the redistributable files in the %VCINSTALLDIR%Redist\MSVC\v142 folder. In both Visual Studio 2017 and Visual Studio 2019, they're also found in %VCToolsRedistDir%. In Visual Studio 2015, these files can be found in %VCINSTALLDIR%redist\, where is the locale of the redistributable packages.


The Visual C++ Redistributable Packages install and register all Visual C++ libraries. If you use one, run it as a prerequisite on the target system before you install your application. We recommend that you use these packages for your deployments because they enable automatic updating of the Visual C++ libraries. For an example about how to use these packages, see Walkthrough: Deploying a Visual C++ Application By Using the Visual C++ Redistributable Package.


Each Visual C++ Redistributable package checks for the existence of a more recent version on the machine. If a more recent version is found, the package won't get installed. In Visual Studio 2015 or later, Redistributable packages display an error message stating that setup failed. If a package is run by using the /quiet flag, no error message is displayed. In either case, an error is logged by the Microsoft installer, and an error result is returned to the caller. In Visual Studio 2015 and later, you can avoid this error by checking the registry to find out if a more recent version is installed. The current installed version number is stored in the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64 key. The version number is 14.0 for Visual Studio 2015, 2017, 2019, and 2022 because the latest Redistributable is binary compatible with previous versions back to 2015. The key is arm64, x86, or x64 depending on the installed vcredist versions for the platform. (You need to check under the Wow6432Node subkey only if you're using Regedit to view the version of the installed x86 package on an x64 platform.) The version number is stored in the REG_SZ string value Version and also in the set of Major, Minor, Bld, and Rbld REG_DWORD values. To avoid an error at install time, you must skip installation of the Redistributable package if the currently installed version is more recent.


The Visual C++ Redistributable supports several command-line options. The /?, /h, or /help options display a pop-up dialog that lists the available options. You may specify /install to install, /repair to repair, or /uninstall to uninstall the Redistributable. The /layout option copies the complete contents of the Redistributable in the current directory. By default, the Redistributable installs its contents and prompts the user for information and whether to restart after installation. You can specify the /passive option, which displays progress, but doesn't otherwise require user interaction. You can also specify a /quiet option, which doesn't display any UI or require any user interaction. The /norestart option suppresses any attempts to restart. By default, a log file is created in %TEMP%. You can use /log filename.txt to log to a specific file.


Merge modules (.msm files) for Visual C++ Redistributable files are deprecated. We don't recommend you use them for application deployment. Instead, we recommend central deployment of the Visual C++ Redistributable package. Central deployment by a Redistributable package makes it possible for Microsoft to service runtime library files independently. And, an uninstall of your app can't affect other applications that also use central deployment. When you use a Redistributable package for central deployment, you aren't responsible for tracking and maintaining the runtime libraries. Otherwise, an update to the runtime library files requires you to update and redeploy your .msi installer. Your app could be vulnerable to bugs or security issues until you do.


Redistributable merge modules must be included in the Windows Installer package (or similar installation package) that you use to deploy your application. For more information, see Redistributing by using merge modules. For an example see Walkthrough: Deploying a Visual C++ application by using a setup project.


It's also possible to directly install the Redistributable DLLs in the application local folder. The application local folder is the folder that contains your executable application file. For servicing reasons, we don't recommend you use this installation location.


If Windows can't find one of the Redistributable library DLLs required by your application, it may display a message similar to: "This application has failed to start because library.dll was not found. Reinstalling the application may fix this problem."


To resolve this kind of error, make sure your application installer builds correctly. Verify that the Redistributable libraries get deployed correctly on the target system. For more information, see Understanding the Dependencies of a Visual C++ Application.


You can build C and C++ applications on the command line by using tools that are included in Visual Studio. The Microsoft C++ (MSVC) compiler toolset is also downloadable as a standalone package. You don't need to install the Visual Studio IDE if you don't plan to use it.


This article is about how to set up an environment to use the individual compilers, linkers, librarian, and other basic tools. The native project build system in Visual Studio, based on MSBuild, doesn't use the environment as described in this article. For more information on how to use MSBuild from the command line, see MSBuild on the command line - C++.


When you choose one of the C++ workloads in the Visual Studio Installer, it installs the Visual Studio platform toolset. A platform toolset has all the C and C++ tools for a specific Visual Studio version. The tools include the C/C++ compilers, linkers, assemblers, and other build tools, and matching libraries and header files. You can use all of these tools at the command line. They're also used internally by the Visual Studio IDE. There are separate x86-hosted and x64-hosted compilers and tools to build code for x86, x64, ARM, and ARM64 targets. Each set of tools for a particular host and target build architecture is stored in its own directory.


To work correctly, the tools require several specific environment variables to be set. These variables are used to add the tools to the path, and to set the locations of include files, library files, and SDKs. To make it easy to set these environment variables, the installer creates customized command files, or batch files, during installation. You can run one of these command files to set a specific host and target build architecture, Windows SDK version, and platform toolset. For convenience, the installer also creates shortcuts in your Start menu. The shortcuts open developer command prompt windows by using these command files for specific combinations of host and target. These shortcuts ensure all the required environment variables are set and ready to use.

3a8082e126
Reply all
Reply to author
Forward
0 new messages