NuGet 无法识别解决方案根文件夹中的 $(SolutionDir) 变量

NuGet does not recognize $(SolutionDir) variable at solution root folder

我使用中央包文件夹已经有一段时间了(使用 %AppData%/NuGet/NuGet.config),但是对于某些要求,我现在需要为某个解决方案使用解决方案级包存储库。

为此,我创建了这个 NuGet.config 并将其放在解决方案根目录中。

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <packageRestore>
    <!-- Allow NuGet to download missing packages -->
    <add key="enabled" value="True" />

    <!-- Automatically check for missing packages during build in Visual Studio -->
    <add key="automatic" value="True" />
  </packageRestore>

  <config>
    <add key="repositoryPath" value="$(Solutiondir)\Packages" />
  </config>

  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>

</configuration>

然而,有趣的是,创建了一个名为 $(Solutiondir) 的文件夹,其中包含存储包的 Packages 文件夹。

我做错了什么?

NuGet 不支持此功能。该路径可以是完整的目录路径,也可以是相对于 NuGet.Config 文件本身的路径。

您可以通过在其 .nuget 目录或解决方案目录中为每个解决方案创建一个 NuGet.Config 文件来获得所需的行为。然后指定相对于 NuGet.Config 文件的目录。