Have a managed application display a meaningful message box when no .NET is installed?
Having written a small .NET Windows Forms 2.0 application, I try to avoid shipping the .NET Framework Redistributable (~20 MB) to keep the size small.
What I can do is to use NSIS to make an installer which checks for installed .NET and download it on demand.
Now I asked myself whether a "poor man's" error checking could be built right into the .NET executable itself?
Kind of like having an unmanaged part that checks for .NET, and a managed part that is the application itself.
Is such a thing possible? I would be rat开发者_运维知识库her statisfied if I could even configure a single message text that is displayed when started without .NET.
No way. The .NET application is a .NET application and the launcher cannot execute the .NET code if no .NET is installed. What you can actually do is wrap the .NET application with unmanaged code - write a simple C++ application and embed your .NET application as a binary resource and, in the main code, check the registry, if the registry is there, save the .net resource to the disk, create a process, set all the parameters (like current folder, command line parameters if necessary) and launch the process. If not - show the message.
You could easily write an executable in a complied language that checks for the .net runtime, but even that is not as easy as its sounds. If you are not careful in writing the unmanaged app you will end up needed to install the vcrt redisturbutable any way making your effort useless.
You can include small framework setup from network package. If you don't like this solution you also can create setup project, which will check for .net framework. Or create msi install with other software.
精彩评论