构建系统瞄准多的.NET版本版本、系统、NET

2023-09-03 20:53:05 作者:情话腻心

什么是设计构建系统/项目结构,允许针对多个.NET版本具有不同功能集常见的做法?

What are common practices for designing a build system/project structure that allows targeting multiple .NET versions with different feature sets?

具体做法是:

如果您在源代码控制分支? 您应该使用条件编译? 您应该导出接口,从而版本呢? 如果您创建单独的versionX项目和链路公共项目文件?

推荐答案

我试着这样做的几个不同的方式。

I've tried a few different ways of doing this.

我排除了分支,因为它是一个有点难以保持同步使用SVN / TFS所有分支。分布式SCC确实有分支/合并更高级的支持,所以我打算重新考虑这种方法,如果我曾经转换。

I ruled out branching because it's a bit difficult to keep all the branches in sync using SVN/TFS. Distributed SCC does have more advanced support for branching/merging, so I'm planning to reconsider this approach if I ever convert.

我用随使用链接的源文件版本,具体项目的条件编译。最激进的图书馆,我沿着这些线路做的是 Nito.Linq ,这尚未发布。您可以检查出的来源,不过,看到我是如何设置的项目。它目前主要用于 3.5,4.0,SL3和SL4,并有以接收和无接收变种为每个这些。我有CF 3.5工作为好,但VS2010不支持它。

I use conditional compilation along with version-specific projects using linked source files. The most aggressive library I've done along these lines is Nito.Linq, which hasn't been released yet. You can check out the source, though, to see how I've set up the projects. It currently targets 3.5, 4.0, SL3, and SL4, and has "with Rx" and "without Rx" variants for each of these. I had CF 3.5 working as well, but VS2010 doesn't support it.

有一些缺点,以这种方式:

There are a few drawbacks to this approach:

在我的解决方案,我定义了一个源项目,该项目作为一个容器中的文件。不幸的是,它的建成加载,当它卸载我无法添加源文件时,所以它最终凑了过来。 链接的源文件中针对不同的框架,为项目引起了另一个问题:它是不可能在不同的项目中打开同一个源文件。 VS会通知你的事实,然后显示来自另一个项目已经打开源文件。这会影响智能感知,特别是与条件编译。不是作秀,塞,但很多时候,你会打开一个文件,然后将其关闭并重新打开它(再回去的地方,你的位置)。 在VS2010 在单元测试都针对4.0框架。等其他框架版本的任何测试,必须在非VS2010方式进行。我还没有发现这个还没有一个很好的解决方案;它不影响Nito.Linq因为单元测试的4.0变种测试所有的code。 In my solution, I defined a "Sources" project that acts as a container for the files. Unfortunately, it's built when loaded and I can't add source files when it's unloaded; so it ends up getting in the way. Linking the source files in projects targeting different frameworks causes another problem: it's not possible to open the same source file in different projects. VS will inform you of the fact and then show the already-open source file from another project. This affects IntelliSense, especially with the conditional compilation. Not a show-stopper, but many times you'll open a file and then have to close it and re-open it (and then go back to the position where you were). Unit tests on VS2010 have to target the 4.0 framework. So any testing on other framework versions has to be done in a non-VS2010 way. I haven't found a good solution for this yet; it doesn't affect Nito.Linq because unit testing the 4.0 variants tests all the code.

我没有问接收团队他们是如何处理这种情况下,(他们支持3.5,4.0 ,SL3和SL4使用相同的codeBase的)。显然,他们使用自定义的内部工具来创建运行时组件只包含元数据的版本,然后将这些成含合并仅元数据集的超集瞩目。该项目是建立在这样的超集,配置文件和编译后重新定位是为了项目的轮廓改变正常的配置文件之一。

I did ask the Rx team how they handled this situation (they support 3.5, 4.0, SL3, and SL4 with the same codebase). Apparently, they use a custom in-house tool to create metadata-only versions of the runtime assemblies and then combine these into a superset-profile containing the merged metadata-only assemblies. The project is built against this superset-profile and a post-compilation "retargeting" is done to change the project's profile to one of the normal profiles.

我简要发挥各地以建设一个开源相当于接收的团队的工具,但遇到了太多的underdocumented碰壁。它应该可以在理论上,但我想它会采取太多的时间,没有任何人在微软内部正确的联系人。

I briefly played around with building an open-source equivalent of the Rx team's tool, but ran into too many "underdocumented" snags. It should be possible in theory, but I figured it would take way too much time for anyone without the correct contacts inside Microsoft.