.Net“任何框架”配置
我用 C# .NET 2.0 构建了一个程序,该程序在框架 3.0 和 3.5 下也能很好地工作。
但如果.NET Framework 4.0是唯一安装的框架,则它不起作用,需要用户安装2.0。
我在google中找到了以下配置:
<startup>
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
</startup>
将其添加到app.config后,我的程序可以在.NET Framework 4.0上运行,没有任何问题!
我正在寻找的是.NET“任何框架”配置,如果安装了.NET 2.0,则在.NET 2.0下运行我的程序,否则在.NET 4.0中运行。
如何做到这一点?
I built a program in C# .NET 2.0 that works great also under framework 3.0 and 3.5.
But if .NET Framework 4.0 is the only framework installed, it does not working, it requires the user to install 2.0.
i found the following configuration in google:
<startup>
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
</startup>
After adding this to the app.config, my program works on .NET Framework 4.0 without any problems!
What i searching for is a .NET 'Any Framework' configuration, that run my program under .NET 2.0 if installed, or else in .NET 4.0.
How to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果没有设计配置,这将无法工作。 .NET 4 使用不同的运行时,当您加载 .NET 2 程序集时,默认情况下,它会在 CLR 版本 2 中加载它。您可以重新配置它以防止这种行为,并将其加载到 CLR v4 中 - 但这并不总是一个好主意。它会导致您编写的代码在与设计和测试代码的框架不同的框架上运行,这可能会出现问题。
在系统上安装适当的要求通常会更容易、更好。安装 .NET 2 非常简单(Vista+ 上默认安装)。这样做的优点是可以在程序设计的框架上运行程序。
This doesn't work without configuration by design. .NET 4 uses a different runtime, and when you load a .NET 2 assembly, by default, it loads it in version 2 of the CLR. You can reconfigure it to prevent this behavior, and have it load in v4 of the CLR - but it's not always a good idea. It causes the code you write to be run on a framework different than the one on which it was designed and tested, which can potentially be problematic.
It's typically easier and better to just install the proper requirements on the system. Installing .NET 2 is very easy (and comes by default on Vista+). This has the advantage of running your program on the framework for which it was designed.
找到了!
以下是所有需要的人的配置:
Found it!
Here is the configuration for all who need it:
很难找到一台只安装了 4.0 的机器。 Vista和Win7机器上预装了.NET 2.0兼容版本,它们可以顺利运行您的程序。您必须拥有一台从未安装过 .NET 的原始 XP 计算机。也许是服务器核心。在这种情况下,有人因为安装了错误版本的 .NET 而犯了一些错误。
不知道这是怎么发生的,闻起来像是沟通问题。也许你不应该让别人来犯这个错误。当您的应用程序的系统要求包括对 XP 的支持时,您最好确保它可用。使用安装项目非常简单。
否则您的 app.config 是错误的,
自 .NET 1.0 以来已过时。正确的咒语是
并要求 2.0.50727 和 4.0It is very hard to find a machine that only has 4.0 installed. .NET 2.0 compatible versions are pre-installed on Vista and Win7 machines, they'll run your program without a hitch. You'd have to have a virgin XP machine that never had .NET installed. Maybe a server core. In which case somebody made a bit of a blunder by installing the wrong version of .NET.
Not sure how that happened, smells like a communication problem. Maybe you shouldn't leave it up to somebody else to get this wrong. When the system requirements for your app include support for XP then you'd better make sure it is available. Pretty simple with a Setup project.
Your app.config is otherwise wrong,
<requiredRuntime>
has been obsolete since .NET 1.0. The proper incantation is<requestedRuntime>
and ask for both 2.0.50727 and 4.0您需要更改申请的最低要求的事情。
转到项目设置,将目标框架更改为 2.0,我认为即使用户系统中有 2.0 或 4.0 Net 框架,它也能发挥相同的作用
the thing you need to change the minimum requirement for application.
go to project setting change the target framework to 2.0 and i thing it's play same even user have 2.0 or 4.0 Net framework in their system