当未安装 .NET 时,托管应用程序是否会显示有意义的消息框?
在编写了一个小型 .NET Windows Forms 2.0 应用程序后,我尝试避免发布 .NET Framework Redistributable (~20 MB) 以保持较小的大小。
我能做的是使用 NSIS 制作一个安装程序,检查已安装的 .NET 并按需下载。
现在我问自己是否可以将“穷人”的错误检查直接内置到 .NET 可执行文件本身中?
有点像有一个检查 .NET 的非托管部分和一个应用程序本身的托管部分。
这样的事可能吗?如果我什至可以配置在没有 .NET 的情况下启动时显示的单个消息文本,我会感到非常满意。
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 rather statisfied if I could even configure a single message text that is displayed when started without .NET.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
决不。 .NET 应用程序是 .NET 应用程序,如果未安装 .NET,则启动程序无法执行 .NET 代码。您实际上可以做的是使用非托管代码包装 .NET 应用程序 - 编写一个简单的 C++ 应用程序并将您的 .NET 应用程序作为二进制资源嵌入,然后在主代码中检查注册表,如果注册表存在,则保存 .NET 应用程序。 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.
您可以轻松地用编译语言编写可执行文件来检查 .net 运行时,但即便如此也不像听起来那么容易。如果您在编写非托管应用程序时不小心,您最终将需要以任何方式安装 vcrt redisturbutable,从而使您的努力毫无用处。
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.
您可以包含网络包中的小型框架设置。如果您不喜欢这个解决方案,您还可以创建安装项目,它将检查 .net 框架。或者使用其他软件创建 msi 安装。
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.