使用 MsBuild 4.0 编译的程序集是否与仅具有 .NET 3.5 的计算机兼容?
在目标框架为 3.5 的项目中,以下行使用 MsBuild 4.0 进行编译:
aEnumerable.Select(aMethod);
但 MsBuild 3.5 要求我编写:
aEnumerable.Select(item => aMethod(item));
两个二进制文件都将运行没有 .NET Framework 4.0 但有 .NET 3.5 的计算机吗?
PS:虽然我展示了一个使用“方法重载推理”的示例,但其他“4.0”功能(例如“命名参数”)也会发生同样的情况。
这个问题的另一个标题可能是:哪些 C# 4.0/Visual Studio 2010 功能与 .NET 3.5 兼容?
In a project which target framework is 3.5 the following line compiles with MsBuild 4.0:
aEnumerable.Select(aMethod);
But MsBuild 3.5 requires me to write:
aEnumerable.Select(item => aMethod(item));
Will both binaries will run a machine without .NET Framework 4.0, but with .NET 3.5?
PS: While i showed an example using "method overload inference" the same happens with other "4.0" features (eg. "named parameters").
another title for this question could be: What C# 4.0/Visual Studio 2010 features are .NET 3.5 compatible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您混淆了 Msbuild 和 .NET 框架。
Msbuild 只是构建 .NET 项目的工具。构建 .NET 4 项目需要版本 4.0,但它也可以构建 .NET 1.1、2.0、3.0、3.5、3.5 SP1。 这就像使用 Word 2010 打开 Word 2003 文件一样。 2010 将打开两者,但如果您给它一个 2010 文件,2003 将崩溃
您的代码示例显示了 4.0 版本中添加到框架中的差异。您无法在未安装 .NET 4.0 框架的计算机上执行 .NET 4 代码。无论用什么构建它,运行时都无法理解 CLR,并且它不会运行
至于 msBuild 本身:
MsBuild 4.0是一个新版本,主要更新为支持.NET 4,但也具有自己的功能。如果需要这些详细信息,请参阅 msbuild4 的发行说明。
也就是说,只要正确配置了 targetFramework,MsBuild 4 就完全能够生成 .NET 3.5 输出。 (早在我们将所有项目升级到 .NET 4 框架之前,我们就将所有构建迁移到了 MsBuild 4.0)
You are confusing Msbuild and the .NET framework.
Msbuild is just a tool to build .NET projects. Version 4.0 is required to build .NET 4 projects, but it can also do .NET 1.1, 2.0, 3.0, 3.5, 3.5 SP1. Its just like using Word 2010 to open a Word 2003 file. 2010 will open both, but 2003 will crash if you give it a 2010 file
Your code examples are showing differenecs added to the framework in version 4.0. You cannot execute .NET 4 code on a machine that doesn't haven't the .NET 4.0 framework installed. Doesn't matter what builds it, the runtime will not be able to understand the CLR and it won't run
As for msBuild itself:
MsBuild 4.0 is a new version, largely updated to support .NET 4, but also with its own features. Consult the release notes for msbuild4 if you need those details.
That said, MsBuild 4 is fully capable of producing .NET 3.5 output so long as the targetFramework is properly configured. (We moved all our builds to MsBuild 4.0 long before we upgraded all projects to the .NET 4 framework)
如果您的安装目标是 .NET 3.5 SP 1 并且它可以工作,那么它将在仅具有 .NET 3.5 Service Pack 1 的计算机上工作。如果您的目标不是 3.5 SP1,则应该如此。
来源
我推测 MSBuild 4 将更新为也支持 .NET Framework 4.0。当然,您应该自己在虚拟机上测试您的安装并确保一切正常。
我只是想澄清一下,如果您想消除否则可能出现的任何兼容性问题,您应该使用 MsBuild 3.5 方法。我怀疑 MSBuild 4.0 会保留对旧方法的支持,但只是进行了更新以支持 4.0 .NET Framework 中发生的更改。
来源
If you target the installation to .NET 3.5 SP 1 and it works then it will work on a machine with just .NET 3.5 Service Pack 1. If your not targeting 3.5 SP1 you should.
Source
I would extrapulate that MSBuild 4 would be updated to also support .NET Framework 4.0. You should of course test your installations yourself a virtual machine and make sure everything works.
I just wanted to clarify that you should be using the MsBuild 3.5 method if you want to remove any compability issues that might arise otherwise. I suspect that MSBuild 4.0 would keep support for the older method but was just updated to support changes that happen in the 4.0 .NET Framework.
Source