简体   繁体   English

您可以将 .net 3.5 DLL 与 .net 2.0 网站一起使用吗?

[英]Can you use a .net 3.5 DLL with a .net 2.0 website?

I have some DLLs that it would be much easier to use .net 3.5 internally (to take advantage of Linq, etc).我有一些 DLL,在内部使用 .net 3.5 会更容易(利用 Linq 等)。 I want to use these DLL with asp.net websites that are currently running asp.net 2.0.我想将这些 DLL 与当前运行 asp.net 2.0 的 asp.net 网站一起使用。

Is this scenario possible?这种情况可能吗? Are there any restrictions or gotchas (eg asp.net doesn't make any calls to methods which return .net 3.5 objects like IQueryable)?是否有任何限制或陷阱(例如 asp.net 不会对返回 .net 3.5 对象(如 IQueryable)的方法进行任何调用)?

Note: Of course, .net 3.5 will be installed on the server.注意:当然,.net 3.5 将安装在服务器上。

To expand on what foosnazzy said, .NET 3.5 (SP1) is just .NET 2.0 SP2 with some new assemblies.为了扩展 foosnazzy 所说的内容,.NET 3.5 (SP1) 只是带有一些新组件的 .NET 2.0 SP2。 The only reason not to install it on the web site would be if the web site would not run with .NET 2.0 SP2.不在 web 站点上安装它的唯一原因是,如果 web 站点无法与 .NET 2.0 SP2 一起运行。

This is very different from the way it used to be - installing .NET 1.1 on a .NET 1.0 web site I was responsible for broke the web site, even though the web site wasn't using 1.1 - I had installed 1.1 so I could use a particular tool. This is very different from the way it used to be - installing .NET 1.1 on a .NET 1.0 web site I was responsible for broke the web site, even though the web site wasn't using 1.1 - I had installed 1.1 so I could use a特定的工具。 The upgrade from .NET 1.1 to .NET 2.0 was an even worse nightmare.从 .NET 1.1 升级到 .NET 2.0 是一场更糟糕的噩梦。

But Microsoft learned from this.但微软从中吸取了教训。 .NET versions from 2.0 .NET 3.5 SP1 all use the .NET 2.0 Common Language Runtime (CLR).从 2.0 .NET 3.5 SP1 开始的 .NET 版本都使用 .NET 2.0 公共语言运行时 (CLR)。 In fact, people who have installed 3.5 are often surprised to look at the IIS settings and see that their web sites still show as running .NET 2.0.事实上,安装了 3.5 的人经常会惊讶地看到 IIS 设置并看到他们的 web 站点仍然显示为运行 .NET 2.0。 But it's the exact same .NET 2.0, just with two service packs applied.但它与 .NET 2.0 完全相同,只是应用了两个服务包。 Any site that doesn't use the new assemblies can't be affected at all (beyond what a service pack might do).任何不使用新程序集的站点都不会受到影响(除了服务包可能会做的事情)。

To further reiterate what has been said - the C# 3.0 features are independant of the Framework.进一步重申已经说过的内容 - C# 3.0 功能独立于框架。 For instance, you can use anonymous types and lambdas in pure .NET 2.0 code.例如,您可以在纯 .NET 2.0 代码中使用匿名类型和 lambda。 What you can't do is use LINQ, since that requires the new assemblies in .NET 3.5.不能做的是使用 LINQ,因为这需要 .NET 3.5 中的新组件。

You can use many features of C# 3 in .net 2.0, but Linq is not one of them.您可以在 .net 2.0 中使用 C# 3 的许多功能,但 Linq 不是其中之一。 You have to include the Linq DLL's, which you are not allowed to distribute seperately and must install the full 3.5 runtime.您必须包含 Linq DLL,不允许单独分发,必须安装完整的 3.5 运行时。

NOTE: If .net 3.5 is installed, I think you will have trouble if the site is not configured to include assemblies from 3.5.注意:如果安装了 .net 3.5,我认为如果站点未配置为包含 3.5 的程序集,您将遇到麻烦。 It may work in a Web Application project (as opposed to a Web Forms project) since the dll's are compiled beforehand and may include the necessary references in the PE files, but i'm not sure.它可以在 Web 应用程序项目中工作(而不是 Web Forms 项目),因为我在 PE 文件中预先编译了 dll 并且可能包含必要的参考文件,但不确定。

3.5 adds to the 2.0 framework, everything is fully backwards compat. 3.5 添加到 2.0 框架,一切都完全向后兼容。

There's always LinqBridge , which allows you to use Linq To Objects in a.Net 2.0 environment.总是有LinqBridge ,它允许您在 a.Net 2.0 环境中使用 Linq To Objects。 However there are some caveats around using it with ASP.Net, depending on whether you use ASP.NET Web Application or ASP.NET Web Site projects. However there are some caveats around using it with ASP.Net, depending on whether you use ASP.NET Web Application or ASP.NET Web Site projects. See this page for more information.请参阅此页面了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM