能否将 .net 3.5 DLL 与 .net 2.0 网站一起使用?
我有一些 DLL,在内部使用 .net 3.5 会更容易(以利用 Linq 等)。 我想将这些 DLL 与当前运行 asp.net 2.0 的 asp.net 网站一起使用。
这种情况可能吗? 是否有任何限制或陷阱(例如,asp.net 不会对返回 .net 3.5 对象(如 IQueryable)的方法进行任何调用)?
注意:当然,服务器上会安装.net 3.5。
I have some DLLs that it would be much easier to use .net 3.5 internally (to take advantage of Linq, etc). I want to use these DLL with asp.net websites that are currently running asp.net 2.0.
Is this scenario possible? Are there any restrictions or gotchas (e.g. asp.net doesn't make any calls to methods which return .net 3.5 objects like IQueryable)?
Note: Of course, .net 3.5 will be installed on the server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
总有 LinqBridge,它允许您在 .Net 2.0 环境中使用 Linq To 对象。 但是,将其与 ASP.NET 一起使用时有一些注意事项,具体取决于您使用的是 ASP.NET Web 应用程序还是 ASP.NET 网站项目。 有关详细信息,请参阅此页面 。
There's always LinqBridge, which allows you to use Linq To Objects in a .Net 2.0 environment. 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.
为了扩展 foosnazzy 所说的内容,.NET 3.5 (SP1) 只是带有一些新程序集的 .NET 2.0 SP2。 不在网站上安装它的唯一原因是网站不能与 .NET 2.0 SP2 一起运行。
这与以前的方式非常不同 - 在我负责的 .NET 1.0 网站上安装 .NET 1.1 破坏了该网站,即使该网站没有使用 1.1 - 我已经安装了 1.1,所以我可以使用特定的工具。 从 .NET 1.1 升级到 .NET 2.0 是一场更糟糕的噩梦。
但微软从中吸取了教训。 从 2.0 .NET 3.5 SP1 开始的 .NET 版本均使用 .NET 2.0 公共语言运行时 (CLR)。 事实上,安装了 3.5 的人常常会惊讶地查看 IIS 设置并发现他们的网站仍然显示为运行 .NET 2.0。 但它与 .NET 2.0 完全相同,只是应用了两个服务包。 任何不使用新程序集的站点根本不会受到影响(超出了服务包可能造成的影响)。
进一步重申已说过的话 - C# 3.0 功能独立于框架。 例如,您可以在纯 .NET 2.0 代码中使用匿名类型和 lambda。 您不能做的是使用LINQ,因为这需要.NET 3.5中的新程序集。
To expand on what foosnazzy said, .NET 3.5 (SP1) is just .NET 2.0 SP2 with some new assemblies. 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.
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. The upgrade from .NET 1.1 to .NET 2.0 was an even worse nightmare.
But Microsoft learned from this. .NET versions from 2.0 .NET 3.5 SP1 all use the .NET 2.0 Common Language Runtime (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. But it's the exact same .NET 2.0, just with two service packs applied. 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. For instance, you can use anonymous types and lambdas in pure .NET 2.0 code. What you can't do is use LINQ, since that requires the new assemblies in .NET 3.5.
您可以在 .net 2.0 中使用 C# 3 的许多功能,但 Linq 不是其中之一。 您必须包含 Linq DLL,您不允许单独分发该 DLL,并且必须安装完整的 3.5 运行时。
注意:如果安装了 .net 3.5,并且站点未配置为包含 3.5 中的程序集,我认为您将会遇到麻烦。 它可能在 Web 应用程序项目(而不是 Web 窗体项目)中工作,因为 dll 是预先编译的并且可能在 PE 文件中包含必要的引用,但我不确定。
You can use many features of C# 3 in .net 2.0, but Linq is not one of them. You have to include the Linq DLL's, which you are not allowed to distribute seperately and must install the full 3.5 runtime.
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. 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.
3.5 添加到 2.0 框架,一切都完全向后兼容。
3.5 adds to the 2.0 framework, everything is fully backwards compat.