Required Components
The following components are required to complete this step-by-step guide:
- A computer with Visual Studio 2022 installed. Installation must include development of computers with C++ workloads and MFC C++ for the latest build tools version 143 (x86 and x64) optional component;
- Microsoft Visual Studio Installer Project Extension. This extension is provided to developers using Visual Studio for free. It adds template functions to Visual Studio for installation and deployment projects;
- To test the deployment, another computer is installed on which Visual C++ libraries are not installed.
Installing C++ and MFC in Visual Studio 2022
If you have installed Visual Studio but do not have C++ or MFC components installed, you can add them.
- Launch the Visual Studio Installer program from the Windows menu;
- In the Visual Studio Installer, click the Change button next to the installed version of Visual Studio;
- In the Modify dialog box, on the Workloads tab, scroll down to the Develop Desktops with C++ tile. If the check box tile is not check, check the check box is check;
- On the side of the dialog box under “Installation Details” expand the “Desktop Development” node using the C++ node , and then expand the “Optional ” node. If it is not already checked, add a check to MFC C++ for latest build tools version 143 (x86 and x64);
- Click the “Change” button to customize the Visual Studio installation. When the installation is complete, close the Visual Studio installer.
Adding application components to the installation project
- In the File System Editor (MyMFCAppSetup) window, select the file system node or application target folder node of the computer>;
- From the menu bar, select “Add Project Output>” to open the Add>Project Output Group dialog box;
- In the dialog box, select “Primary Output ” and click the OK button. A new item named Primary Output from ProjectName (Active) will appear in the file system window;
- Right-click the Application Folder node and select Add>Assembly to open the Select Component dialog box. Select and add the necessary DLL libraries required by the program. For more information on how to define the required libraries, see “Defining distributed DLLs”;
- In the list of items in the application folder, right-click Primary Output from ProjectName (Active) and select “Create a shortcut for Primary Output” from ProjectName (Active). A new item named Shortcut to Primary Output from ProjectName (Active) will appear. Give this shortcut a different name, then drag it to the user’s Programs Menu node on the left side of the window. This item causes a shortcut to be created for the application in the menu;
- From the menu bar, select Build>Configuration Manager to open the Configuration Manager dialog box;
- In the Configuration Manager dialog box, in the Project table in the build column, check the field for the deployment project. Click Close to save your changes and close the dialog box;
- From the menu bar, sequentially select Build>Collect Solution to build the MFC project and the deployment project;
- In the solution folder, locate the setup.exe program created by the deployment project. This file can be copied (and the .msi file) to install the application and its required library files on another computer.
Perform deployment testing
To test the deployment, copy the deployment files to a second computer that does not have the Visual C++ libraries installed. Run the deployment program. If the application loads and runs normally, and you do not receive a runtime error about missing libraries or components, the deployment is successful.
To test applications, you can create a deployment installer that installs a debug version of the application along with the debug libraries on the computers you manage. Debugging applications and debug libraries are not licensed for distribution and cannot be deployed on client computers.