两个project.json文件可以共享同一代码库吗? [英] Can two project.json files share the same codebase?

查看:91
本文介绍了两个project.json文件可以共享同一代码库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码库,我想从中构建.NET Core库和UWP库。最初,我想构建一个可以同时为两者使用的库,但是我没有找到解决办法(在UWP的情况下,该库需要引用UWP特定的类,例如StreamSocket)。 b $ b

因此,我为UWP创建了一个单独的项目文件。但是,看起来我无法创建单独的project.json(我无法拥有core.json和uwp.json,因为project.json名称是恒定的)。而且我不想在不同的文件夹中创建我的代码库的多个副本(每个副本都有自己的project.json),我宁愿保留一个副本。



某种方式可行吗?

解决方案

最简单的方法是拥有三个库:

  MyLib.Common 
MyLib.Core
MyLib.Uwp

保留MyLib.Common中所有共享的,与平台无关的代码,并从两个特定于平台的项目中引用该代码。这样,您几乎不需要重复代码,也可以从UWP项目中引用特定于UWP的库,而不会出现任何问题。



您也许还可以获得两个项目引用相同的 .cs 文件(并删除共享项目),但对我来说似乎更hackable。


I have some codebase from which I want to build a .NET Core library and a UWP library. Initially, I wanted to build a single lib which would serve for both but I didn't find a way for this (in UWP case, the lib needs to reference UWP specific classes like StreamSocket).

So I created a separate project file for UWP. However, looks like I can't create a separate project.json (I can't have core.json and uwp.json because project.json name is constant). And I don't want to create multiple copies of my codebase (each one with its own project.json) in different folder, I'd rather keep a single copy.

Is it feasible somehow?

解决方案

The cleanest way to achieve this would be to have three libraries:

MyLib.Common
MyLib.Core
MyLib.Uwp

Keep all of the shared, platform-neutral code in MyLib.Common, and reference that from the two platform-specific projects. This way, you have little or no code duplication, and you can also reference UWP-specific libraries from the UWP project without any problems.

You might also be able to get two projects to reference the same .cs files (and get rid of the shared project), but that seems more hackish to me.

这篇关于两个project.json文件可以共享同一代码库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆