Create a text file named AppIcon.rc, with the following content.
1 ICON "AppIcon.ico"
You will need an icon file named AppIcon.ico for this to work, but of course you can adjust the names to your liking.
Run the following command.
"C:\Program Files (x86)\Windows Kits\10\bin\x64\rc.exe" /v AppIcon.rc
If you can't find rc.exe in this location, then search for it below C:\Program Files (x86)\Windows Kits. If you still can't find it, then download Windows SDK from Microsoft.
A file named AppIcon.res will be generated.
In Visual Studio, open the project properties. Select the Application page.
In the text box titled Resource File, type AppIcon.res (or Images\AppIcon.res if you put it there), and then close the project properties to save.
An error message will appear, stating "The resource file entered does not exist. Ignore this. The error message will not reappear.
Rebuild. The executable will then have an application icon, and this shows in File Explorer. When running, this icon will also appear in Task Manager.