开发者

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

开发者 https://www.devze.com 2023-01-01 19:14 出处:网络
I thought that latest Matlab does this automatically. I have tested the following exe on a clean Win XP VM:

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 fa开发者_Go百科iled 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消