如何获取针对 .Net 4 的代码库以与 .Net 3.5 应用程序一起使用

发布于 2024-10-10 05:49:40 字数 264 浏览 0 评论 0原文

我正在构建一个新的代码库,并希望使用 .Net 4 作为我的目标框架,因为我的所有新应用程序都将使用 .net 4。我的旧版 Web 应用程序使用 .Net 3.5。我想将此代码库用于我的所有应用程序。

此时,我只看到 2 个选项

  1. 为我需要的每个框架编译 dll,每次更改目标框架
  2. 使用不同的目标框架创建单独的项目。

有什么办法可以解决这个问题,让我的代码库是一次编译吗?不知道 4 中是否内置了一些东西来允许这样的事情。

I'm building a new code library and would like to use .Net 4 as my target framework as all my new apps will use .net 4. My legacy web apps use .Net 3.5. I want to use this code library for all of my apps.

At this point, I see only 2 options

  1. Compile the dll for each framework I need, changing the target framework each time
  2. Create separate projects with differing target frameworks.

Is there any way around this so my code library is a single compile? Didn't know if there was something built into 4 to allow something like this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2024-10-17 05:49:40

为什么不直接针对 .NET 3.5 构建您的库呢?

  • 如果他们尝试使用 .NET 4 功能,那么显然它们无论如何都不适用于您的 .NET 3.5 Web 应用程序
  • 如果不是,那么使用 .NET 3.5 应该没问题

关于互操作和混合模式程序集有一些警告,但对于纯 C# 程序集来说,这应该不是问题。

可能针对不同版本的框架有不同的构建配置,但这有点痛苦 - 您需要手动处理项目文件。请参阅 MiscUtil 的项目文件作为示例。

我不明白为什么您对之前的 .NET 2 / .NET 3.5 情况感到满意 - 它与之前的情况并没有太大的不同。

当然,更新您的 Web 应用程序以在 .NET 4 上运行可能是未来最好的解决方案。

Why not just build your libraries against .NET 3.5?

  • If they're trying to use .NET 4 features then obviously they won't work against your .NET 3.5 webapps anyway
  • If they're not, then using .NET 3.5 should be fine

There are some caveats around interop and mixed-mode assemblies, but for pure-C# assemblies it shouldn't be a problem.

It's possible to have different build configurations targeting different versions of the framework, but a bit of a pain - you'll need to mess with the project files manually. See the project files for MiscUtil as an example.

I don't see why you were happy with the .NET 2 / .NET 3.5 situation before - it's not very significantly different to that.

Of course, updating your webapps to run on .NET 4 would probably be the best solution, going forward.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文