英文:
create c# .dll compatible on both .net3.5 and .net4.0
问题
I have to create a dll written on c#. The dll will have to be used on two different types on machines:
-MachineA that has got .net35 installed, but .net40 is not installed
-MachineB that has bot .net40 installed, but .net35 is not installed
Currently there is no option to install .net35 on MachineB, or to install .net40 on MachineA.
I would assume that creating a dll on .net35 would be able to be run on MachineB. But when I try to call any of the dll's functions, I get an error saying that the application needs .net35 to be installed
So the question is this: Is it possible to create the dll in a way that it will be compatible on both MachineA and MachineB?
英文:
I have to create a dll written on c#. The dll will have to be used on two different types on machines:
-MachineA that has got .net35 installed, but .net40 is not installed
-MachineB that has bot .net40 installed, but .net35 is not installed
Currently there is no option to install .net35 on MachineB, or to install .net40 on MachineA.
I would assume that creating a dll on .net35 would be able to be run on MachineB. But when I try to call any of the dll's functions, I get an error saying that the application needs .net35 to be installed
So the question is this: Is it possible to create the dll in a way that it will be compatible on both MachineA and MachineB?
答案1
得分: 2
你可以通过在 app.config
文件中添加多个 supportedRuntime
值来配置你的应用同时运行在 .NET 的两个版本(3.5 和 4.0)上。
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
.NET Framework 4 及更高版本使用 v4.0
运行时,而 .NET Framework 2.0、3.0 和 3.5 使用 v2.0.50727
运行时。另外,由于你的目标是旧版 .NET 3.5,启用 旧运行时激活策略 useLegacyV2RuntimeActivationPolicy="true"
是有意义的。
上述配置会在 .NET 3.5 上运行你的代码,如果两个版本都安装了,它将在 .NET 4.x 上运行。
你也可以查看这篇 MSDN 文章 获取更多详情。
英文:
You can configure your app to run on both versions of .NET (3.5 and 4.0) by adding multiple supportedRuntime
values in app.config
file
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
.NET Framework 4 and later uses v4.0
runtime, .NET Framework 2.0, 3.0, and 3.5 use v2.0.50727
runtime. Also, since you are targeting old .NET 3.5, it'll make sense to enable old runtime activation policy, useLegacyV2RuntimeActivationPolicy="true"
.
The configuration above runs your code on .NET 3.5, if only this version is installed. In case of both versions installed it'll will run on .NET 4.x
Yo can also have a look at this MSDN article for more details
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论