针对多个框架,如何实现?
我在 Mercurial 代表中有 ac# 库(在 VS2010 中开发),当前针对 netFX-3.5。我想在我的库中使用 netFX-4.0 中的一些功能,但由于有很多项目仅限于 2.0 CLR,所以我还想保留和维护 netFX-3.5 版本。当然,两个版本中都会有一些相同的代码(甚至可能是大部分代码)。现在我很困惑这是维持这一点的最佳(或至少是好的)方法。
我应该在VS中创建一个单独的项目吗?或者也许创建存储库的克隆?有一些行之有效的策略吗?
更新: 我发现 VS 添加为链接 功能,允许共享项目之间的文件,这对于在同一解决方案中将两个目标实现为两个项目来说是一个巨大的优势。我很确定我会采用这个解决方案,但如果有更多建议,那就太好了!
更新2: 正如我之前所说,使用“添加为链接”功能来实现预期结果,如下所示:为旧的 (3.5) 框架创建一个新项目。将所有文件添加为顶级版本项目的链接。在 v4.0 项目中,通过 Partial class
规范(例如 ClassName.Net40.cs
)将 netFX-4.0 功能添加到类中。对我来说效果很好。
I have a c# library (developing in VS2010) in Mercurial rep, which currently targets netFX-3.5. There are some features in netFX-4.0 which I want to use in my library, but since there is lot of projects which are limited to 2.0 CLR I also want to keep and maintain netFX-3.5 version. Naturally there will be some code (maybe even most of the code) which will be identical in both versions. Now I'm puzzled that is the best (or at least good) way to maintain this.
Should I create a separate project in VS? Or maybe create a clone of repository? Is there some proven strategies for that?
Update:
I've found VS Add as Link feature, which allows a sharing of a file between projects, which is a huge plus towards implementing two targets as a two projects in the same solution. I'm pretty sure I go with this solution, but if there are some more advices, it would be great!
Update2:
As I've said earlier, used Add as link feature to achive deired result as follows: create a new project for an old (3.5) framework. Add all files as a link from top version project. In v4.0 project add netFX-4.0 features to a class via partial class
specification like ClassName.Net40.cs
. Works fine for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常人们通过 MSBUID 目标来完成此操作,但是,微软最近发布了一些非常酷的“便携式库工具”Visual Studio 扩展,它添加了一个与类库非常相似的新项目类型,但已经拥有支持多个框架的基础设施,甚至包括银光,WP7。
检查http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/
Usually people do it via MSBUID targets, however, Microsoft has recently released some very cool "Portable Library Tools" Visual Studio extension, which adds a new project type very similar to class library, but already has the infrastructure to support multiple frameworks, even including Silverlight, WP7.
Check http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/
我不知道有什么经过验证的策略,因为这实际上取决于什么会有所不同以及如何不同。在不具体了解的情况下,我可以提供一些可能会有所帮助的想法。
#if
一种方法是为 .NET 3.5 和 .NET 4.0 创建单独的构建配置,以便您可以在每个构建配置中指定单独的条件编译符号,并在某些位置执行类似的操作:
构建配置可以轻松地从一个构建配置切换到一个构建配置。另一个并立即建造所有这些。然而,它们主要对代码有帮助。
MQ
我为一个项目执行此操作的方式(有一段时间,我需要 .NET 3.5 版本的 Caliburn.Micro)是使用 Mercurial 队列来获得一个补丁,我可以在存储库上应用该补丁以“降级”内容。使用 MQ 是解决方案的必要部分,因为我仍然需要能够更新 CM 存储库的克隆并重新应用我的更改。
条件编译对我没有帮助的另一个原因是,CM 对 Blend SDK Interactivity 程序集的引用需要更改为以前的版本,而且我不知道如何在项目文件中进行条件引用。
(如果您以前没有使用过 MQ:MqTutorial 和章节 12 & 13 Mercurial:权威指南。)
I don't know about any proven strategy, because it really depends on what will be different and how. Without knowing specifically, I can offer a couple ideas that will probably help.
#if
One way is to create separate build configurations for .NET 3.5 and .NET 4.0 so that you can specify separate conditional compilation symbols in each build configuration and do things like this in certain places:
Build configurations make it easy to switch from one to another and to build all of them at once. They're mainly helpful with code, however.
MQ
The way that I did this for one project (for a while, I needed a .NET 3.5 version of Caliburn.Micro) was to use Mercurial Queues to have a patch I could apply over the repository to "downgrade" things. Using MQ was a necessary part of the solution because I still needed to be able to update my clone of the CM repository and re-apply my changes.
Another reason conditional compilation wouldn't help me help here is that CM's reference to the Blend SDK Interactivity assembly needed to change to a previous version, and I didn't know how to do conditional references in the project file.
(If you haven't used MQ before: MqTutorial, and Chapters 12 & 13 of Mercurial: The Definitive Guide.)