为什么UWP类库项目的引用会被复制到主项目中?

3
我遇到了一个与通用 Windows 平台相关的问题,让我感到非常困扰。
假设我的解决方案中有两个项目——第一个是通用 Windows 应用程序(TestApp),第二个是通用 Windows 类库(TestClassLibrary)。 TestApp 引用了 TestClassLibrary。TestClassLibrary 引用了 Newtonsoft.Json NuGet 包(也可以是其他任何包)。

enter image description here

现在是奇怪的部分。 TestClassLibrary 中的任何引用都变成了对 TestApp 的公共引用。我可以在 TestApp 类中使用任何 NewtonsoftJson 特定的命名空间,尽管 TestApp.csprojproject.json 都没有任何与 Newtonsoft.Json 相关的引用。这违反了 TestClassLibrary 的封装性,使其实现细节(即引用的库)变为公共的,而我不希望如此。
问题是 - 这是 UWP 类库的一个特性,我在哪里可以阅读相关信息?还是这是 NuGet 的错误?
1个回答

1

TestClassLibrary内的任何引用都将对TestApp公开。我可以在TestApp类中使用任何NewtonsoftJson特定的命名空间。

我可以按照以下步骤重现此问题:

  1. 创建两个项目,按照您的示例确保选中以下选项。 enter image description here
  2. Intellisense在TestApp项目中无法为Newtonsoft.Json工作。但是,TestApp构建成功。

    enter image description here

  3. 重新打开解决方案,Intellisense和构建都有效。

    enter image description here

这应该是一个NuGet的问题,我在Nuget GitHub issues页面上找到了一个类似的开放问题 (https://github.com/NuGet/Home/issues/1629)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接