如何获取针对 .Net 4 的代码库以与 .Net 3.5 应用程序一起使用
我正在构建一个新的代码库,并希望使用 .Net 4 作为我的目标框架,因为我的所有新应用程序都将使用 .net 4。我的旧版 Web 应用程序使用 .Net 3.5。我想将此代码库用于我的所有应用程序。
此时,我只看到 2 个选项
- 为我需要的每个框架编译 dll,每次更改目标框架
- 使用不同的目标框架创建单独的项目。
有什么办法可以解决这个问题,让我的代码库是一次编译吗?不知道 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
- Compile the dll for each framework I need, changing the target framework each time
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不直接针对 .NET 3.5 构建您的库呢?
关于互操作和混合模式程序集有一些警告,但对于纯 C# 程序集来说,这应该不是问题。
可能针对不同版本的框架有不同的构建配置,但这有点痛苦 - 您需要手动处理项目文件。请参阅 MiscUtil 的项目文件作为示例。
我不明白为什么您对之前的 .NET 2 / .NET 3.5 情况感到满意 - 它与之前的情况并没有太大的不同。
当然,更新您的 Web 应用程序以在 .NET 4 上运行可能是未来最好的解决方案。
Why not just build your libraries against .NET 3.5?
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.