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

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

问题描述

我有一些代码库,我想从中构建一个 .NET Core 库和一个 UWP 库.最初,我想构建一个可以同时用于两者的库,但我没有找到方法(在 UWP 情况下,库需要引用 UWP 特定类,如 StreamSocket).

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).

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

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.

它以某种方式可行吗?

推荐答案

实现这一目标的最简洁方法是拥有三个库:

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

MyLib.Common
MyLib.Core
MyLib.Uwp

在 MyLib.Common 中保留所有共享的、平台中立的代码,并从两个特定于平台的项目中引用这些代码.这样,您几乎没有或没有代码重复,而且您还可以毫无问题地从 UWP 项目中引用 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.

您也许还可以让两个项目引用相同的 .cs 文件(并摆脱共享项目),但这对我来说似乎更hackish.

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天全站免登陆