如何指示 RestorePackages 使用 NuGet.config 文件的 repositoryPath 作为包输出路径?

How to instruct RestorePackages to use the NuGet.config file's repositoryPath for the package output path?

我正在尝试将基于 CCNET 的构建脚本迁移到基于 F# Fake 的构建脚本。我很难理解如何修改 RestorePackages 方法以遵循 NuGet.config 文件,该文件指示 NuGet 将包放置在我们存储库深处的名为 'External' 的文件夹中。

NuGet.config 示例:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="Code\DotNet\External\" />
  </config>
</configuration>

NuGET CCNET 示例:

<exec executable="Tools\NuGet\nuget.exe">
    <buildArgs>restore $[$CCNetWorkingDirectory]\Code\DotNet\Web\All.sln</buildArgs>
</exec>

在上面的示例中,我只是告诉 NuGet 恢复解决方案中所有项目的包。这符合 NuGet.config.

中的设置

NuGet 假例子: 目标 "RestorePackages"(有趣 _ -> 恢复包() )

但是,调用 RestorePackages() 尊重 NuGet.config(因为此方法仅使用默认参数),因此我的包在错误的位置更新。

理想情况下,我想指示 RestorePackages 专门查看 Visual Studio 解决方案文件,就像我对 CCNET 所做的那样。这可能吗?

如果那不可行,我想指示 RestorePackages 遵守 NuGet.config 文件中的设置。

但是,如果两者都不可行,我将需要能够覆盖输出路径。不幸的是,我很难理解 the documentation,而且我不确定如何构造它。

我一直在阅读 RestorePackagesHelper 模块的 documentation and the source code,发现它不支持我想要实现的目标,至少由于两个限制而不是直接支持。

限制 1:不支持解决方案文件 - 当前的 RestorePackage 实现使用 NuGet Install Command which does not support passing in a solution file. In order to pass in a solution file one would need to use the NuGet Restore Command。因此,对于问题中列出的 CCNET 片段,这不是直接的 Fake 等价物。

限制 2:不支持 ConfigFile - 此外,RestorePackageParams 类型没有 ConfigFile 参数,因此我无法指定要用于 NuGet 的 ConfigFile恢复。

这些是 Fake 的当前限制。不是 NuGet。

合理的解决方案 - 但是,我可以通过扫描给定目录中的所有 packages.config 文件并为每个文件调用 RestorePackage 来实现与 Fake 类似的效果;每次指定 OutputPath 如下所示。

伪造的 NuGet RestorePackages 示例

Target "RestorePackages" (fun _ ->
    !! "./**/packages.config"
        |> Seq.iter (RestorePackage (fun p ->
            { p with
                OutputPath = "./Code/DotNet/External"}))
)