在 cproj 文件中将引用标记为 developmentOnly?

Marking a reference as developmentOnly in cproj file?

来自 this post:

You reference nuget Jetbrains.Annotations, and DO NOT define JETBRAINS_ANNOTATIONS: Such annotations are useful only for developers working with source code, they are not compiled in your binary (Conditional statement is used) and they are not visible when referencing your dll. You can even add developmentOnly="true" attribute to Jetbrains.Annotations in packages.config, so by default it would not be treated as dependency.

在我的 cproj 文件中我有:

<Reference Include="JetBrains.Annotations, Version=10.2.1.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
  <HintPath>..\..\Build Files\packages\JetBrains.Annotations.10.2.1\lib\net\JetBrains.Annotations.dll</HintPath>
  <Private>True</Private>
</Reference>

我能否完全摆脱此引用并依赖 packages.config 条目:

  <package id="JetBrains.Annotations" version="10.2.1" targetFramework="net45" developmentOnly="true" />

如果 cproj 文件已经引用了 packages.config,那么在 packages.config 和 cproj 文件中包含引用的目的是什么?

csproj文件中的引用用于表示.dll文件的提示路径。从Jetbrains.Annotations库中调用Class和属性时需要指定路径。

并且 package.config 文件由 NuGet 基础结构管理。它用于跟踪和恢复已安装的软件包及其各自的版本。 See here 有关 packages.config 的一些详细信息。

所以它们有不同的用法,你不能完全去掉这个引用,只能依赖 packages.config 条目。