bypass .Net not installed scenario - by embedding C# appl. inside C++ appl.?

I have a smallish C# application that i wish to distribute as a standalone executable (ie. without installer or other support files). Easy enough if everyone has .Net Framework 2.0 installed as it's a simple question of file copy/mail/web-publish/etc.

The problem is when the application is run by someone who doesn't have .Net installed, it exits without any visible error (except for an obsecure entry in the event log). Needless to say, this is not very helpful :<

A workaround i had thought was to embed the c# application in a thin C++ Win32 application, the latter of which simply detects the present of .Net installed;
a) not installed - prompts the user for action (ie. instead of just quietly aborting)
b) is installed - extract embedded c# application to file (or can this also be done to memory ) and execute the application.

Questions;
1. How to embed c# .exe in non .Net C++ application
2. Am i doing this hard way and maybe there is an easier way (but not using an installer solution)

Cheers.
--
stoj




Answer this question

bypass .Net not installed scenario - by embedding C# appl. inside C++ appl.?

  • MuniHemadriBabu.Jogi

    Agreed, that creating a setup.exe with a .Net bootstrap is certainly the traditional method for distributing full blown applications.

    However as per my above post, due to the overhead (ie. both increase in size for attached bootstrap and time/fuss required to install application) creating a setup.exe style installation file is what i'm *deliberately* trying to avoid.

    I would of hoped that this is a pretty standard design pattern and definitely not considered a hack akin to html's pattern; "if no support installed (eg. playing .wmv files) then do this (eg. show link to install support)"



  • Santiago Ace&amp;#241;olaza

    The officially supported way of distributing software is to use Windows Installer, i.e. build a .MSI. One of the reasons for this is that an MSI can detect whether pre-requisites are installed or not. (And you can decide whether to simply display an error, or to provide a means of installing the prereqs.)

    If you're just distributing a standalone executable then you're pretty much on your own. In Windows, dependency management is handled at installation time, not runtime.

    In short, if you want "If no support installed then do this..." behaviour, MSI's the standard way to support this standard design pattern.

    You don't need to do a bootstrap by the way. You can just build an MSI. And if you want to avoid the overhead of including a copy of your prereqs, you're free to do that - you can build an MSI that checks to see if the prereqs are present and shows a link to them if they are not. This means your MSI barely needs to be any bigger than the EXE. (In fact with compression, the MSI may be smaller.)

    That said, you could hack something together that does what you want. You could write a C++ application that checked for the presence of the .NET framework, and which contained a copy of the .NET executable as a binary resource - it could copy the file out to a temp directory and run it when the .NET framework is present.

    But there are no standard tools for doing that, because that's not the official way to do that. The official way to do that is to build an MSI.


  • JustinParkes

    Check out the .NET bootstrapper which chains installing .NET and your application.

    Anything else is just a hack.

    http://msdn.microsoft.com/vstudio/downloads/tools/bootstrapper/



  • thechristopher

    Thanks for the info. Grudgingly, i will see how lightweight (and hopefully transparent) i can get an MSI install.

    Out of interest, using non .Net aware C (Win32) or C++ (MFC)non does anyone know how to embed a resource file using visual studio 2005 and subsequently detach the resource file at run time Easy enough with .Net's manifest class functionality, but i have yet to see how to do it without .Net libraries.

    Cheers.



  • bypass .Net not installed scenario - by embedding C# appl. inside C++ appl.?