C# 我可以将 System.Core.dll (.net 3.5) 的引用添加到 .net 2.0 应用程序并使用它吗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/823024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:01:22  来源:igfitidea点击:

Can I add a reference to System.Core.dll (.net 3.5) to a .net 2.0 application and use it

c#timetimezone

提问by

Can I add a reference to System.Core.dll (.net 3.5) to a .net 2.0 application and use it

我可以将 System.Core.dll (.net 3.5) 的引用添加到 .net 2.0 应用程序并使用它吗

I am trying to use the TimeZoneInfo class which is available in .net 3.5 only, by referencing System.Core.dll

我正在尝试通过引用 System.Core.dll 来使用仅在 .net 3.5 中可用的 TimeZoneInfo 类

Alternatively, is their an alternate for TimeZoneInfo in .net 2.0 (or a customised class)

或者,它们是 .net 2.0 中 TimeZoneInfo 的替代品(或自定义类)

回答by JaredPar

No you really should not. You mustinstall 3.5 on the target machine or you will run into unpredictable behavior in the running program. The 3.5 framework including System.Core.dll depend on several bug fixes / features that were added to CLR 2.0 SP1 (this is a part of 3.5 framework). If you run against an unpatched CLR you will be essentially running untested code and will likely hit several bugs.

不,你真的不应该。您必须在目标机器上安装 3.5,否则您将在正在运行的程序中遇到不可预测的行为。包括 System.Core.dll 在内的 3.5 框架依赖于添加到 CLR 2.0 SP1(这是 3.5 框架的一部分)的几个错误修复/功能。如果您针对未打补丁的 CLR 运行,您实际上将运行未经测试的代码,并且可能会遇到几个错误。

回答by NotDan

I'm not sure if you can do this with System.Core.dll, but we have done this before with the Linq2Sql dlls for a .net 2.0 application. .net 3.5 uses the same version of the CLR with new assemblies built upon the .net 2.0 runtime. If you can get all of the dependencies, it mightwork. As I said, this worked for us with Linq2Sql dlls, but is not guaranteed for all scenarios. (For example, you probably wont be able to get WPF to run on Windows 2000, but you might be able to get Linq to Objects to work)

我不确定您是否可以使用 System.Core.dll 来做到这一点,但我们之前已经使用 .net 2.0 应用程序的 Linq2Sql dll 做到了这一点。.net 3.5 使用相同版本的 CLR 和基于 .net 2.0 运行时构建的新程序集。如果您可以获得所有依赖项,它可能会起作用。正如我所说,这对我们使用 Linq2Sql dll 有效,但不能保证适用于所有场景。(例如,您可能无法让 WPF 在 Windows 2000 上运行,但您可能能够让 Linq to Objects 工作)

回答by Rex M

Scott Hanselman wrote a blog post describinghow to run an early version of MVC on the 2.0 framework. He noted that the dependencies on System.Core will probablybe OK as long as you are very careful not to call any routines that depend on CLR features specific to 3.0+ (for example, LINQtoSQL).

Scott Hanselman写了一篇博客文章,描述了如何在 2.0 框架上运行早期版本的 MVC。他指出,只要您非常小心地不调用任何依赖于特定于 3.0+ 的 CLR 功能的例程(例如,LINQtoSQL),对 System.Core 的依赖关系可能没问题。

He rightlyplastered the blog post with disclaimers that it is notsupported, it very well might not work for you, but he got it to work and if you can, then yay for you.

正确地贴满了博客文章与免责声明,它是支持的,它很可能已经不适合你的工作,但他它得到的工作,如果可以的话,那么耶为您服务。

回答by Software Enthusiastic

.net 3.5 runs on .net 2.0 runtime. So you should be able to use it... But referencing a single dll would lead to unexpected behaviour as you don't know all the dependencies system.core.dll have.... I would recommend not to do that...

.net 3.5 在 .net 2.0 运行时上运行。所以你应该可以使用它......但是引用单个 dll 会导致意外行为,因为你不知道 system.core.dll 的所有依赖项......我建议不要这样做......

回答by saret

You can do this, currently doing the same thing for a tool for work - also to utilize the TimeZoneInfo stuff. As long as thats all you're using you shouldn't run into any issues (at least I haven't).

您可以这样做,目前正在为工作工具做同样的事情 - 也可以利用 TimeZoneInfo 的东西。只要这就是您使用的全部内容,您就不应该遇到任何问题(至少我没有)。

However I'm not entirely sure of the legalities of bundling System.Core with your app. From what I know you're not allowed to.

但是,我并不完全确定将 System.Core 与您的应用程序捆绑在一起的合法性。据我所知,你是不允许的。

I ended up utilizing the one from Mono for the tool that uses it.

我最终将 Mono 中的一个用于使用它的工具。