Click here to Skip to main content
15,795,233 members
Articles / Desktop Programming / MFC

Deploying MFC applications via ClickOnce

Rate me:
Please Sign up or sign in to vote.
4.86/5 (32 votes)
14 Jan 2008CPOL5 min read 88.1K   56   14
A step by step tutorial on how to deploy an MFC application via ClickOnce

Image 1


Recently I had the task of deploying an MFC application suite along with its dependencies via ClickOnce. Visual Studio does not directly support deployment of MFC applications (even if it's compiled with /clr) and one of the suggested solutions I found on the web was to have a stub C# executable which would launch the main MFC application. That way you could take advantage of Visual Studio's built-in deployment functionality. My friend Rama Vavilala had a better suggestion for me - he asked me to try putting in a dummy cpp file into the main project that was compiled using /clr. If ClickOnce accepted such an executable as a .NET assembly, then all I would have to do would be to create the required manifest files on my own. Well all I can say is hats off to Rama for his elegant solution - because it actually did work. This article is a step-by-step pictorial on how you would deploy an MFC application using this trick.

Steps to deploying the MFC app

For my example I will use a simple MFC dialog application - but you can use the same technique with a real application with dependencies (both managed and native) and it will work (and I have got it to work).

Step 1 - Add the dummy /clr file

Add a new cpp file to your project and leave it empty. Change its compilation setting to use /clr and remove support for precompiled headers. You would also have to tweak a couple of other settings to allow the /clr compilation mode depending on your main project settings. Now build the app. Even though you have an empty /clr cpp unit in the project, you'll find that the app is a .NET app for all purposes (you can verify this by opening the app in reflector).

Step 2 - Create a deployment folder and share it

Obviously in your case your deployment folder may be an FTP URL or a web URL - so please change it accordingly. I just used a shared network path in my machine. I created a folder called AppDeploy (which was shared using the same name on the network) and I copied the MFC application into that folder. If you have dependencies, you need to copy those files to the folder too.

Step 3 - Create the application manifest

Image 2

You don't need to do this from scratch. Instead you can use the mageui utility to create a default app manifest. The first step would be to specify the name of the application, the version, and the processor type. See the screenshot where I've highlighted out the relevant changes.

Step 4 - Populate the files

Image 3

You can auto-populate the required files by specifying the application directory. It will auto-detect the main application (though if you have multiple executables, you might need to manually fix this).

Step 5 - Signing the app manifest

Image 4

You can leave the rest of the settings as they are and save the file - you'll get a sign dialog as shown above. Since this is the first time, use the [New] button to create a new certificate. If your company has a real certificate to use, then you'd obviously be using that instead.

Step 6 - Creating the deployment manifest

Image 5

The next step is to create the deployment manifest, using the same name and version as the application manifest. Remember to set the processor to x86.

Step 7 - Setting the app description

Image 6

This step is optional, but this is the information that the ClickOnce dialog will show the end-user when he tries to run the app. So you might want to put some decent information in there.

Step 8 - Setting ClickOnce deployment options

Image 7

I've chosen install locally - so the app gets cached each time (unless there's a newer version out). I've also set a start location for the ClickOnce application. Your URL would obviously be different.

Step 9 - Setting the update options

Image 8

I've used the default update options, but you can play with these settings to find one that better suites your needs.

Step 10 - Referencing the app manifest

Image 9

This is where you associate the app manifest with the deployment manifest. The mageui utility will fill up the required information automatically from the manifest.

Step 11 - Save and sign the deployment manifest

You can use the same key you used earlier to sign the manifest during saving. Note that you can use a different key to sign the deployment manifest if you want that.


That's it. You can try running the application via the ClickOnce URL and you'll see that the app deploys and runs fine.

Updating the manifests via a batch file

If you update the executable or one of its dependencies, you'll find that it's not enough to just update the deployment folder. You have to re-sign the manifests and also add newly added dependencies. You will also need to change the version number to let ClickOnce correctly update the local version with an update from the server. I've written a simple batch file that you can use. Please change the folder and file names accordingly. The batch file (Update.bat) looks as shown below :-

@call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86

mage -u ".\MfcDialog\MFC Application.exe.manifest" -fd .\MfcDialog\ -v %1

mage -u ".\MfcDialog\MFC Application.exe.manifest" -cf .\MfcApp.pfx

mage -u .\MfcApp.application -appm ".\MfcDialog\MFC Application.exe.manifest" -v %1

mage -u .\MfcApp.application -cf .\MfcApp.pfx

I've used the command line mage utility (mageui is basically a UI version of mage - now there's a surprise!). The first call to mage updates the files and sets the version on the app manifest. The next call signs the app manifest. Then we run mage again, this time on the deployment manifest, so it correctly updates the app manifest details. And finally, we sign the deployment manifest. You have to sign both manifests each time as the file contents change whenever you change anything.

You can run it via the command like as :-


Typical output would be :-

Setting environment for using Microsoft Visual Studio 2008 x86 tools.
MFC Application.exe.manifest successfully updated
MFC Application.exe.manifest successfully signed
MfcApp.application successfully updated
MfcApp.application successfully signed

Okay. That's it really. You can play with and tweak various options to match your requirements. If you have any suggestions, feedback or criticism, those are welcome. I hope someone gets some use out of this article - since I am not very sure that there are going to be lots of folks who want to use ClickOnce for deploying their MFC applications.


  • Rama Vavilala (blog) - For the dummy /clr trick


  • Jan 12, 2008 - First version of the article


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United States United States
Nish Nishant is a technology enthusiast from Columbus, Ohio. He has over 20 years of software industry experience in various roles including Chief Technology Officer, Senior Solution Architect, Lead Software Architect, Principal Software Engineer, and Engineering/Architecture Team Leader. Nish is a 14-time recipient of the Microsoft Visual C++ MVP Award.

Nish authored C++/CLI in Action for Manning Publications in 2005, and co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his WordPress blog. Nish is experienced in technology leadership, solution architecture, software architecture, cloud development (AWS and Azure), REST services, software engineering best practices, CI/CD, mentoring, and directing all stages of software development.

Nish's Technology Blog :

Comments and Discussions

QuestionHow to deploy with prerequisites Pin
Anup Walvekar7-Oct-16 2:40
Anup Walvekar7-Oct-16 2:40 
QuestionIssue of MFC application deployment using mageUI.exe Pin
Member 1019433530-Dec-15 1:17
Member 1019433530-Dec-15 1:17 
QuestionEntry point problem Pin
Member 891995220-Nov-14 0:38
Member 891995220-Nov-14 0:38 
GeneralDeploying MFC applications via click once Pin
crowsfoot24-Nov-09 1:48
crowsfoot24-Nov-09 1:48 
GeneralSetup of MFC feature pack application Pin
sandeeprattu8-Sep-09 21:32
sandeeprattu8-Sep-09 21:32 
GeneralProgram distribution to end users fails Pin
AlexEvans10-Aug-09 13:30
AlexEvans10-Aug-09 13:30 
GeneralThanks very much - it is a life saver for me (if it works - not tried yet) Pin
jshenj20-Feb-09 10:30
jshenj20-Feb-09 10:30 
GeneralI don't understand your instructions Pin
David Fenstemaker29-Sep-08 6:38
David Fenstemaker29-Sep-08 6:38 
Generalsign the application manifest Pin
anup nambiar19-May-08 14:10
anup nambiar19-May-08 14:10 
QuestionReading emails from Thunderbird Pin
Gul Mohammad24-Feb-08 21:59
Gul Mohammad24-Feb-08 21:59 
Generalinstall path Pin
Jadhao9-Feb-08 14:47
Jadhao9-Feb-08 14:47 
GeneralGood information Pin
Hans Dietrich14-Jan-08 5:07
mentorHans Dietrich14-Jan-08 5:07 
GeneralRe: Good information Pin
hw7704126-Sep-09 10:21
hw7704126-Sep-09 10:21 
GeneralNice article Pin
Jim Crafton14-Jan-08 4:33
Jim Crafton14-Jan-08 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.