How to use VS to package C++ programs

introduction

I wrote a snake game in C++ under VS. It runs and debugs well, but the generated exe application has no background image and music, and even the wall is gone. So Baidu took a look at how VS packaged programs. Most of the articles said that they were not careful. Let me share my experience below.

environment

Operating System : Windows 11 Home Chinese Edition 21H2
System Version : 22000.978
VS Version : Visual Studio 2022 4.8.04161
Program Language : C++

Pack

1. Install the packaging tool that comes with VS

Open VS, open the project to be packaged, click the extension at the top , and click Manage Extensions .
insert image description hereFind Microsoft Visual Studio Installer Projects 2022 in the management extension , the picture below is what I have already installed, so there is a green tick in the upper right corner; if it has not been installed: there is a download button in the lower right corner, click the download button, and wait for the download to complete Finally, exit VS, and then a pop-up window will automatically prompt to install the plug-in. The process is only two or three steps, not complicated, just click "Yes" and you are done. After the installation, I restarted the computer (this plug-in should be available without restarting), and reopened VS and the project.
insert image description here

2. Create a new Setup project in the source project

Right-click the solution you created in the Solution Explorer , select Add , select New Project , search for "setup" in the search box, select Setup Project
insert image description here
from the candidates , and click Next . Fill in the project name, select the path to save the Setup project, and click Create . Then the following interface will pop up, you can see that the newly created Setup Project has been added to the solution explorer , and a File System file and 3 folders have been opened. Right-click the solution , click Open Folder in File Explorer , and open the folder where the source project is located. The above Application Folder can be understood to correspond to the source project folder snake, and under the snake folder there are .vs, audio, pic, and x64 folders, so according to the hierarchical relationship, corresponding folders should also be created under the Application Folder folder , but we only care about whether the data such as pictures and sounds outside the program can be loaded into the final program, because my background image is placed in pic, and BGM is placed in audio, so I only need to create pic and audio files under the Application Folder Just clip it. Right-click Application Folder , click Add , and click Folder .
insert image description here

insert image description here

insert image description here

insert image description here
insert image description here

insert image description here
In this way, two folders, audio and pic, are created under the Application Folder.
insert image description here
Right-click the audio folder, click Add , click File ,
insert image description here
add the audio files in the corresponding folder in the source project to the audio folder in the Setup project, and add the image files in the source project folder to Setup in the same way under the pic folder in the project. Since the Snake I wrote and the wall data of the level are placed in the folder at the same level as the source project, it is also necessary to right-click the Application Folder to add the map file. The source project file structure is as follows (you can see that pic, audio, project file and map file [mapx.txt] are at the same level, so files should be added according to this level in the Application Folder):
insert image description here

The result of adding the Application Folder file is as follows:
insert image description here
Added game audio files under the audio folder
The game background picture is added under the pic folder
Finally, click the Application Folder button , click Add , click the project output , select the main output , click OK , and an output type file will be generated under the Application Folder, which is the main program.
insert image description here

3. Add shortcut

Right-click the main program, select Create Shortcut to main output...(Active) , and then a Shortcut type file will be generated, which is the shortcut link:
insert image description here
cut the shortcut link from the Application Folder folder to the User's Desktop folder (in this way When installing the program, a shortcut will be automatically generated on the desktop):
insert image description here

4. Add app icon

The application icons that come with the system are featureless, so you can manually add them as needed. Before modifying the default icon, you need to have an OK icon file (.ico file). Choose a picture you like, try to modify it into a square size of N N, such as 400 400, and then modify the picture into an ico file on any Baidu website that generates ico online. If the picture is not in a square size, the final ico effect may be Flat or thin.
Go back to VS, right-click Application Folder , click Add , click File , and add the generated ico file.
insert image description here

Right-click the shortcut link file, select the property window :
insert image description here
Find the Icon in the miscellaneous items , the default is None, that is, there is no icon, and it will be assigned by the system. Follow the steps in the figure below to manually add the ico file: Click Browse... Double-click Application Folder to select the Application Folder just added ico file in , click OK , so that the application icon is changed from the default to the one you want.
insert image description here

insert image description here

insert image description here

insert image description here

5. Generate program

Right-click the Setup project, click Regenerate , and then generate the .msi file that can be installed in the folder where the Setup Project is saved. Note that if Debug is selected on VS, the generated msi file is in the Debug folder. If it is the selected Release, then it is under the Release folder.
insert image description here
insert image description here
Double-click the msi file, install the generated application, and click the shortcut on the desktop to open the application!

reference video

Link: Software Packaging

Guess you like

Origin blog.csdn.net/peggy201314/article/details/127002250