We have a C# DLL (let's call it myapp.exe
) built with .NET 2.0 Framework (VS2005) and we found out that our application won't work on machines where only .NET 4.0 or above is installed. To let our application work on .NET 4.0, I added the following some lines to myapp.exe.config
by following this article Installing .NET Framework V4.0 and Running .NET 2.0/3.0/3.5/3.5Sp1 Applications
我们有一个c# DLL(我们叫它myapp.exe),它是用。net 2.0框架(VS2005)构建的。为了让我们的应用程序在。net 4.0上运行,我在myapp.exe中添加了以下几行。通过安装。net Framework V4.0并运行。net 2.0/3.0/3.5/3.5 /3.5 sp1应用程序来配置
<startup>
<supportedRuntime version="v4.0.30319"/>
</startup>
And it is working.
它是有效的。
Then I saw that this article also mentioned the following (especially second paragraph):
然后我看到这篇文章也提到了以下(特别是第二段):
Now, I knew that you can’t just take a 3.5 Service Pack 1 application and run it on the V4.0 CLR. It needs a V2.0 CLR or reconfiguring with a tag in order to bend the application to run on the V4.0 CLR and that bending might be something that you don’t want to do.
现在,我知道您不能只使用3.5 Service Pack 1应用程序并在V4.0 CLR上运行它。它需要一个V2.0 CLR或重新配置一个标记,以便使应用程序能够在V4.0 CLR上运行,而这种弯曲可能是您不想做的事情。
What I hadn’t realised though was that installing .NET 4.0 wouldn’t install the bits that you need for a 2.0/3.0/3.5/3.5Sp1 application. It would only install the V4.0 CLR and the V4.0 assemblies and not additionally install the equivalent of .NET Framework V3.5 Sp1. So, you’d need to install (e.g.) .NET Framework V3.5 Sp1 yourself along with .NET 4.0
我没有意识到的是,安装。net 4.0不能安装2.0/3.0/3.5/3.5 /3.5 sp1应用程序所需的位。它只会安装V4.0 CLR和V4.0程序集,而不会额外安装。net Framework V3.5 Sp1。因此,您需要自己安装。net Framework V3.5 Sp1和。net 4.0
From my testing it would mean that I could run my 2.0 C# application on .NET 4.0 with .NET 4.0 framework (4.0 assembly/libraries) which is contradicting to what the articles said.
从我的测试来看,这意味着我可以在。net 4.0上运行我的2.0 c#应用程序,使用。net 4.0框架(4.0 assembly/libraries)),这与文章的内容相矛盾。
Or am I missing something here? It could be helpful if someone could clarify on this. Microsoft doesn't really make this clear at all.
还是我漏掉了什么?如果有人能澄清这一点,可能会有帮助。微软并没有明确这一点。
4 个解决方案
#1
5
From my testing it would mean that I could run my 2.0 C# application on .NET 4.0 with .NET 4.0 framework (4.0 assembly/libraries) which is contradicting to what the articles said.
从我的测试来看,这意味着我可以在。net 4.0上运行我的2.0 c#应用程序,使用。net 4.0框架(4.0 assembly/libraries)),这与文章的内容相矛盾。
You can run your application on .NET 4 using the .NET 4 assemblies. There is always the possibility that there may be a slight change in runtime behavior, however, as you won't be using the same runtime and framework which you used for development. I suspect the article is trying to suggest that you won't get the exact same behavior by just installing 4.0, though, as you've seen, it should work.
您可以使用. net 4程序集在. net 4上运行应用程序。但是,总有可能运行时行为会有轻微的变化,因为您不会使用用于开发的相同的运行时和框架。我怀疑这篇文章试图建议您不要仅仅安装4.0就得到完全相同的行为,但是,正如您所看到的,它应该可以工作。
Doing this is likely fine, though I would recommend doing thorough testing of your application if this is going to be a standard deployment option.
这样做可能很好,但是如果这是一个标准的部署选项,我建议对应用程序进行彻底的测试。
#2
8
And I quote:
和我引用:
"The .NET Framework 4 is backward-compatible with applications that were built with the .NET Framework versions 1.1, 2.0, 3.0, and 3.5. In other words, applications and components built with previous versions of the .NET Framework will work on the .NET Framework 4."
. net Framework 4与. net Framework版本1.1、2.0、3.0和3.5构建的应用程序向后兼容。换句话说,用. net框架的先前版本构建的应用程序和组件将在. net框架4上工作。
Taken from Version Compatibility in the .NET Framework
来自。net框架的版本兼容性
You have the right idea with the App.config file, but your really limiting yourself with the one line.
Might I suggest a more liberal use of supportedRuntime lines?
对于App.config文件,您的想法是正确的,但是您真正的限制是只使用一行。我是否可以建议更*地使用支持性的时间线?
For example:
例如:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<!--
<supportedRuntime version="v3.5"/> "The .NET Framework version 3.0 and 3.5 use version 2.0.50727 of the CLR."
-->
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.1,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.2,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.3,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.3" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Why is supportedRuntime version="v3.5"
commented out? Remember, this configuration identifies which versions of the Common Language Runtime (CLR) your application is compatible with. There is no 3.0 or 3.5 version of the CLR. Refer to .NET Framework Versions and Dependencies
为什么supportedRuntime版本=“v3.5”都被注释掉了?请记住,此配置标识了您的应用程序兼容的公共语言运行时(CLR)的哪个版本。CLR没有3.0或3.5版本。参考。net框架版本和依赖性
#3
1
Just to be a little more concise. In the App.config you are showing support for the CLR. From .Net v2 and on there are only 2 version of the CLR. So the following will give you support of .Net v2 and on. Make sure to include your exe.config file that is built with your project otherwise you are likely to still see the popup asking to install .Net.
为了更简洁一点。在App.config中,您显示了对CLR的支持。从。net v2中,只有2个版本的CLR。下面的内容将为您提供。net v2和on的支持。一定要包括你的前任。与项目一起构建的配置文件,否则您可能仍然会看到弹出窗口请求安装。net。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
For support for .Net v2 to v3.5 use:
支持。net v2到v3.5使用:
<supportedRuntime version="v2.0.50727"/>
For support for .Net v4.0 to 4.6 use:
对于.Net v4.0到4.6的支持:
<supportedRuntime version="v4.0"/>
More information can be found for Configure an App to Support .NET Framework
可以找到更多的信息来配置支持。net框架的应用程序
#4
-3
Just setting web.config to supportedRuntime version="v4.0.30319"/ is not going to be enough.
只是网络设置。配置为supportedRuntime version="v4.0.30319"/是不够的。
You need to actually open up your project in Visual Studio, change its target framework (properties-->build) to 4.0 - and THEN redploy the built solution to your 4.0 clients. Several system assemblies are different between 2.0 and 4.0 (system.web etc..) - although, as the previous answer suggested, backwards compatibility has been provided.
您需要在Visual Studio中实际打开您的项目,将其目标框架(属性——>构建)更改为4.0,然后对您的4.0客户端使用构建的解决方案。一些系统程序集在2.0和4.0之间是不同的(系统)。尽管,正如前面的回答所指出的,向后兼容性已经提供了。
The only way to consistently provide your clients with an actuual '4.0 compatible' version, is to compile it against a 4.0 runtime. This will entail upgrading any 3rd party, open source libraries to their 4.0 versions as well.
要始终为客户提供与4.0兼容的版本,唯一的方法就是在4.0运行时对其进行编译。这也需要将任何第三方、开源库升级到4.0版本。
#1
5
From my testing it would mean that I could run my 2.0 C# application on .NET 4.0 with .NET 4.0 framework (4.0 assembly/libraries) which is contradicting to what the articles said.
从我的测试来看,这意味着我可以在。net 4.0上运行我的2.0 c#应用程序,使用。net 4.0框架(4.0 assembly/libraries)),这与文章的内容相矛盾。
You can run your application on .NET 4 using the .NET 4 assemblies. There is always the possibility that there may be a slight change in runtime behavior, however, as you won't be using the same runtime and framework which you used for development. I suspect the article is trying to suggest that you won't get the exact same behavior by just installing 4.0, though, as you've seen, it should work.
您可以使用. net 4程序集在. net 4上运行应用程序。但是,总有可能运行时行为会有轻微的变化,因为您不会使用用于开发的相同的运行时和框架。我怀疑这篇文章试图建议您不要仅仅安装4.0就得到完全相同的行为,但是,正如您所看到的,它应该可以工作。
Doing this is likely fine, though I would recommend doing thorough testing of your application if this is going to be a standard deployment option.
这样做可能很好,但是如果这是一个标准的部署选项,我建议对应用程序进行彻底的测试。
#2
8
And I quote:
和我引用:
"The .NET Framework 4 is backward-compatible with applications that were built with the .NET Framework versions 1.1, 2.0, 3.0, and 3.5. In other words, applications and components built with previous versions of the .NET Framework will work on the .NET Framework 4."
. net Framework 4与. net Framework版本1.1、2.0、3.0和3.5构建的应用程序向后兼容。换句话说,用. net框架的先前版本构建的应用程序和组件将在. net框架4上工作。
Taken from Version Compatibility in the .NET Framework
来自。net框架的版本兼容性
You have the right idea with the App.config file, but your really limiting yourself with the one line.
Might I suggest a more liberal use of supportedRuntime lines?
对于App.config文件,您的想法是正确的,但是您真正的限制是只使用一行。我是否可以建议更*地使用支持性的时间线?
For example:
例如:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<!--
<supportedRuntime version="v3.5"/> "The .NET Framework version 3.0 and 3.5 use version 2.0.50727 of the CLR."
-->
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.1,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.2,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.3,Profile=Client" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.3" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Why is supportedRuntime version="v3.5"
commented out? Remember, this configuration identifies which versions of the Common Language Runtime (CLR) your application is compatible with. There is no 3.0 or 3.5 version of the CLR. Refer to .NET Framework Versions and Dependencies
为什么supportedRuntime版本=“v3.5”都被注释掉了?请记住,此配置标识了您的应用程序兼容的公共语言运行时(CLR)的哪个版本。CLR没有3.0或3.5版本。参考。net框架版本和依赖性
#3
1
Just to be a little more concise. In the App.config you are showing support for the CLR. From .Net v2 and on there are only 2 version of the CLR. So the following will give you support of .Net v2 and on. Make sure to include your exe.config file that is built with your project otherwise you are likely to still see the popup asking to install .Net.
为了更简洁一点。在App.config中,您显示了对CLR的支持。从。net v2中,只有2个版本的CLR。下面的内容将为您提供。net v2和on的支持。一定要包括你的前任。与项目一起构建的配置文件,否则您可能仍然会看到弹出窗口请求安装。net。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
For support for .Net v2 to v3.5 use:
支持。net v2到v3.5使用:
<supportedRuntime version="v2.0.50727"/>
For support for .Net v4.0 to 4.6 use:
对于.Net v4.0到4.6的支持:
<supportedRuntime version="v4.0"/>
More information can be found for Configure an App to Support .NET Framework
可以找到更多的信息来配置支持。net框架的应用程序
#4
-3
Just setting web.config to supportedRuntime version="v4.0.30319"/ is not going to be enough.
只是网络设置。配置为supportedRuntime version="v4.0.30319"/是不够的。
You need to actually open up your project in Visual Studio, change its target framework (properties-->build) to 4.0 - and THEN redploy the built solution to your 4.0 clients. Several system assemblies are different between 2.0 and 4.0 (system.web etc..) - although, as the previous answer suggested, backwards compatibility has been provided.
您需要在Visual Studio中实际打开您的项目,将其目标框架(属性——>构建)更改为4.0,然后对您的4.0客户端使用构建的解决方案。一些系统程序集在2.0和4.0之间是不同的(系统)。尽管,正如前面的回答所指出的,向后兼容性已经提供了。
The only way to consistently provide your clients with an actuual '4.0 compatible' version, is to compile it against a 4.0 runtime. This will entail upgrading any 3rd party, open source libraries to their 4.0 versions as well.
要始终为客户提供与4.0兼容的版本,唯一的方法就是在4.0运行时对其进行编译。这也需要将任何第三方、开源库升级到4.0版本。