您可以在解决方案中混合使用 .NET 框架版本吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2433108/
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
Can you mix .NET framework Versions in a solution?
提问by Micah
Our codebase where I work is .NET 2.0. For our new assembly/DLLs/web applications I would love to take advantage of what 3.5 has to offer.
我工作的代码库是 .NET 2.0。对于我们新的程序集/DLL/Web 应用程序,我很想利用 3.5 提供的功能。
Can one mix .NET frameworks(per assembly) in a solution? Are there any IIS related caveats to this?
可以在解决方案中混合 .NET 框架(每个程序集)吗?是否有任何与 IIS 相关的警告?
I would love to hear any positive/negative/howto feedback. Let me know!
我很想听到任何积极/消极/如何反馈。让我知道!
Thanks!
谢谢!
采纳答案by Faizan S.
Yes you can do this in Visual Studio and it is called Multi-Targeting.
是的,您可以在 Visual Studio 中执行此操作,它称为Multi-Targeting。
Scott Guthrie has a great blog-entry on Multi-Targeting Support in Visual Studio.
Scott Guthrie 有一篇关于Visual Studio 中多目标支持的很棒的博客条目。
VS 2008 was the first release of Visual Studio that included multi-targeting support for .NET. What this meant was that you could use VS 2008 to create and edit not only .NET 3.5 projects, but also .NET 3.0 and .NET 2.0 projects as well. This allowed developers to more quickly upgrade and take advantage of new Visual Studio tooling features – without having to necessarily require the newer version of .NET to be installed on the clients and production servers running their applications.
VS 2008 是 Visual Studio 的第一个版本,其中包括对 .NET 的多目标支持。这意味着您不仅可以使用 VS 2008 创建和编辑 .NET 3.5 项目,还可以创建和编辑 .NET 3.0 和 .NET 2.0 项目。这使开发人员能够更快地升级并利用新的 Visual Studio 工具功能——而不必在运行其应用程序的客户端和生产服务器上安装较新版本的 .NET。
Cheers
干杯
回答by BG BG
You can use 2.0, 3.0 and 3.5 together according to: http://msdn.microsoft.com/en-us/library/bb383796(v=vs.90).aspx
您可以根据以下内容一起使用 2.0、3.0 和 3.5:http: //msdn.microsoft.com/en-us/library/bb383796(v=vs.90).aspx
回答by kemiller2002
EDIT: I was wrong you can.You can go reference 3.+ assemblies in 2.0, because the CLR is the same. This will not be the case when going from 2.0/3.+ to 4.0 as there is a new version of the CLR.
编辑:我错了,你可以。您可以在 2.0 中引用 3.+ 程序集,因为 CLR 是相同的。从 2.0/3.+ 到 4.0 时不会出现这种情况,因为有一个新版本的 CLR。
http://abdullin.com/how-to-use-net-35-syntax-and-compiler-features-for-net-20/
http://abdullin.com/how-to-use-net-35-syntax-and-compiler-features-for-net-20/
回答by Ross Hambrick
If you can wait for the new .NET 4.0 framework, you will be able to run dll's for each version side by side in the same process.
如果您可以等待新的 .NET 4.0 框架,您将能够在同一进程中并行运行每个版本的 dll。
回答by Hans Passant
This should not be an issue. .NET 2.0 RTM through .NET 3.5 SP2 all use the exact same version of the CLR. They only differ by the number of assemblies that are included. The assembly format is the same. Of course, if you do take advantage of an assembly that's only included with .NET 3.5, you must make sure that 3.5 is actually installed on the target machine. You'll find out quickly if it isn't.
这应该不是问题。.NET 2.0 RTM 到 .NET 3.5 SP2 都使用完全相同的 CLR 版本。它们仅在包含的程序集数量上有所不同。汇编格式是一样的。当然,如果您确实利用了仅包含在 .NET 3.5 中的程序集,则必须确保 3.5 实际安装在目标计算机上。如果不是,您会很快发现。
3.5 should already be on the machine if it has Windows Update enabled. If not, it takes a dozen or so minutes to get it on there.
如果机器启用了 Windows 更新,则 3.5 应该已经在机器上。如果没有,需要十几分钟才能把它放在那里。
回答by quillbreaker
As a side note, we have some old 1.0 libraries that we used in 2.0 and still use in 3.5, without recompiling. So there's some backwards compatibility there.
附带说明一下,我们有一些旧的 1.0 库,它们在 2.0 中使用,在 3.5 中仍然使用,无需重新编译。所以那里有一些向后兼容性。
回答by Justin
You cannot have .Net 1.1 assmeblies running in the same process as a .Net 2.0+ assembly - attempting to do so will produce a failure.
您不能在与 .Net 2.0+ 程序集相同的进程中运行 .Net 1.1 程序集 - 尝试这样做会导致失败。
With regards to IIS, this means that you cannot have .Net 1.1 sites / virtual directories running in the same application pool as .Net 2.0 and above sites - you need to create a separate app pool to keep the .Net 1.1 code running in a different process. (This can only be done in IIS 6.0 and above, i.e. not in Windows XP)
对于 IIS,这意味着您不能在与 .Net 2.0 及更高版本站点相同的应用程序池中运行 .Net 1.1 站点/虚拟目录 - 您需要创建一个单独的应用程序池以保持 .Net 1.1 代码运行在不同的过程。(这只能在 IIS 6.0 及以上版本中完成,即不能在 Windows XP 中完成)
However as nobugz says - .Net 2.0 through to .Net 3.5 all use the same CLR, and so different versions of .Net code can be mixed in the same assembly without worry - this also holds true for IIS (.Net 2.0 and .Net 3.5 code can happily co-exist in the same app pool)
然而正如 nobugz 所说 - .Net 2.0 到 .Net 3.5 都使用相同的 CLR,因此不同版本的 .Net 代码可以毫无顾虑地混合在同一个程序集中 - 这也适用于 IIS(.Net 2.0 和 .Net 3.5 代码可以愉快地共存于同一个应用程序池中)

