ClickOnce Deployment for Unmanaged Code (C++, VB6, etc)

Monday, August 25, 2008 10:53:30 PM (Eastern Standard Time, UTC-05:00)

ClickOnce is a great deployment model for many Windows applications built with the .NET Framework. Too bad it isn't supported for C++, VB 6, or other technologies. Or is it...

Surprisingly, you can deploy your unmanaged apps with ClickOnce. You just need a tiny .NET app to get it started.

Here's how it works:

  1. Take your existing C++ project.

  2. Add to the solution a .NET console application.

  3. Change the project settings on the console application to "Windows Application".

  4. Write the following code for your Main method of your .NET launcher application:
    static void Main(string[] args)
    {
        try
        {
            Process.Start( "TheRealApp.exe" );
        }
        catch ( Exception x )
        {
            string msg = "Error launch application:\n\n" + x;
            string cap = "Error Launching Application";
            MessageBox.Show( msg, cap, MessageBoxButtons.OK, MessageBoxIcon.Error );
        }
    }
    
  5. Set the build path of your C++ app to be in the main folder for your .NET application.

  6. Add the C++ app and its libraries (if any) as existing items in the .NET app.

  7. Change the build action to "Always Copy" as shown here:




  8. Then you publish your .NET application and when it runs, TADA!, the C++ app is deployed, versioned, and kept up to date as well.



If you want to try it yourself, you can run this sample application here:

   Run Michael's Useless C++ App via ClickOnce...

You can also download the source.



Tuesday, October 21, 2008 3:04:19 PM (Eastern Standard Time, UTC-05:00)
This is extremely interesting. Could you please explain what you mean by, "Set the build path of your C++ app to be in the main folder for your .NET application"? How do I do that? Thanks.
Thursday, October 23, 2008 8:03:09 AM (Eastern Standard Time, UTC-05:00)
Sure, you can download the source and see what I've done. But you go to the build part of the C++ project and set it to something like:

..\..\MydotNetApp\

rather than Debug\

Thanks,
Michael
Michael Kennedy
Thursday, October 23, 2008 10:25:55 AM (Eastern Standard Time, UTC-05:00)
Doh. In other words, I have to put the "real" program's files in the .Net project's main folder?

Aside from not understanding that, I can't believe how easy this is, especially after reading the advice on MSDN about making manifests manually for C++ projects. It took me less than ten minutes and I've never written a .Net program before. And it seems to work perfectly from my web site. This was so easy, in fact, that now I'm wondering what the downside is. :)

Thanks very much for your help!

I did have one slight problem -- the compiler keeps telling me that the namespace I looked up for MessageBox can't be found -- but I'll figure it out.

By the way I did download your sample and look at it, but there are so many settings I missed at least one very important one. :)

Thanks again! You saved me a ton of work. Not only initially but (I imagine) a lot of future work that would have been needed to maintain the deployer manually.
Thursday, October 23, 2008 10:36:39 AM (Eastern Standard Time, UTC-05:00)
Er, I meant, put the "real" program's run-time files (exe and whatever else is required at run time) in the .Net project's main folder. I see how it works now.
Comments are closed.