How can I make a .Net 4.0 Exe ask the user to download .Net 4.0 framework / redistributable before running this exe?

StackOverflow https://stackoverflow.com/questions/2960399

سؤال

I thought that latest Matlab does this automatically. I have tested the following exe on a clean Win XP VM:

namespace DotNetTest
{
    using System.Windows.Forms;

    class Program
    {
        static void Main(string[] args)
        {
            MessageBox.Show("Howdy!");
        }
    }
}

When I run it on a computer which has all these installed, it does show the message box and a window. When I run it on a clean VM, I get this error:

Title: DotNetTest.exe - Application Error
Icon: Error
Buttons: {OK}
Message Body: The application failed to initialize properly (0xc0000135). Click on OK to terminate the application.

I would expect better from MSFT geniuses. Why cannot every .Net exe contain a tiny bit of overhead and have the very first bytes of it do the work of detecting if .Net is installed and presenting a better message.

Is there some sort of setting that I can flip to fix this? All of the settings were default ones provided by VS2010 when I created a new project.

Thank you.

هل كانت مفيدة؟

المحلول

As Alexandr says, you should really use the installer for this. If that's not possible, you'd have to write an unmanaged exe to run first and then either start the .net exe or tell the user to download the framework depending on if it's already installed.

نصائح أخرى

This is what you use an installer for. In .net this is simple, you just "publish" your project and you get an installer that makes shure that .net is installed and such. The application itself should never have to worry about that.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top