请提供有关使用 .NET 3.0 语法和编译 2.0 的建议
使用 3.0 编译器构建但针对 2.0 框架的 DLL 一定可以在仅具有 2.0 运行时的机器上运行吗?
详细信息: 迄今为止,我们一直使用 .NET 2.0 编译器进行构建,以确保与 2.0 运行时的兼容性。现在我们想包含一些包含 3.0 语法的第三方源代码,但我们仍然需要与 2.0 运行时兼容。因此,我们正在考虑为我们的生产版本更改为 3.0 编译器,但目标是 2.0 框架。
虽然这看起来应该可行,但有点可怕,所以我们真的很想听听尝试过此操作的人的意见。
Will a DLL built using the 3.0 compiler but targeted at the 2.0 framework definitely run on machines with only the 2.0 runtime?
Details:
To date we've been building using the .NET 2.0 compiler in order to ensure compatibility with the 2.0 runtime. Now we'd like to included some third-party source that contains 3.0 syntax, but we still need to be compatible with the 2.0 runtime. We're therefore considering changing to the 3.0 compiler for our production builds, but targeting the 2.0 framework.
While it seems like this should work, it is a little scary, so we'd really like to hear from someone who's tried this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在仍以 2.0 运行时为目标的情况下使用以下 C# 3 功能:
您可以在 2.0 运行时中使用以下 C# 3 功能 hack:
您不得使用以下内容:
You may use the following C# 3 features while still targeting the 2.0 runtime:
You may use the following C# 3 features with 2.0 runtime with a hack:
You may not use the following:
只要第三方库不引用不在目标运行时中的库,就可以了。 C# 3.0 与 C# 2.0 一样编译为 IL 代码,并且所有语法添加仅限于 C# 语言。
As long as the third party library doesn't reference libraries not in the target runtime, you are fine. C# 3.0 compiles to IL code just as C# 2.0 and all syntactic additions are confined to the C# language only.
没关系。 .NET 3.5 和 C# 3.0 编译器的输出与 .NET 2.0 编译器二进制兼容。
It's fine. .NET 3.5 and the output of the C# 3.0 compiler is binary compatible with the .NET 2.0 compiler.
是的,它会起作用,因为编译器扩展只是语法糖。只需确保它使用正确的服务包即可。
Yes, it will work, because the compiler extensions are just syntactic sugar. Just make sure it's using the correct service pack.