为什么我的 repositoryPath 在 Azure DevOps/TFS 中被忽略?

Why is my repositoryPath ignored in Azure DevOps / TFS?

首先,我有一个 NuGet.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value=".\ExternalReferences\Packages" />
      <solution>
        <add key="disableSourceControlIntegration" value="true" />
      </solution>
  </config>
</configuration>

在我的 dev 分支的根目录中。它的工作是,我的 dev 分支中的每个项目都将包恢复到 \dev\ExternalReferences\Packages,这在本地运行良好。

我正在尝试通过 TFS(VisualStudio 团队 Services/DevOps)为我的 CI-Build.

引入 Azure Pipelines

但是,TFS 将包恢复到错误的文件夹 \dev\packages(其中 \devD:\a\s\)而不是 \dev\ExternalReferences\Packages

Acquired lock for the installation of Newtonsoft.Json 12.0.3
Installing Newtonsoft.Json 12.0.3.
Adding package 'Microsoft.Extensions.Logging.Abstractions.2.2.0' to folder 'D:\a\s\packages'

稍后会破坏构建(需要 ExternalReferences\Packages):

PrepareForBuild:
  Creating directory "bin\Release\".
  Creating directory "obj\Release\".
ResolveAssemblyReferences:
  Primary reference "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL".
##[warning]C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\a\s\Conwell.WebServices.Google\Conwell.WebServices.Google.csproj]

知道如何让 NuGet 恢复到正确的目录吗?

我刚刚为项目类型创建了一个标准管道 Asp.NET

作为解决方法,我直接配置了目录:

转到管道,然后编辑:

转到 NuGet 还原、高级和目标目录:

我仍然对选择持开放态度,这将尊重 NuGet.Config

Why is my repositoryPath ignored in Azure DevOps / TFS?

由于 nuget 恢复任务将包恢复到错误的文件夹 \dev\packages,似乎 NuGet.Config 中的设置 repositoryPath 被忽略了。

要解决此问题,您可以尝试在设置 nuget 还原任务时指定 nuget.config 以确保您已使用 NuGet.Config:

然后我的 nuget.config 看起来像:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AzureDevOpsFeed" value="https://pkgs.dev.azure.com/xxxn/_packaging/xxx/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>

  <config>
    <add key="repositoryPath" value=".\ExternalReferences\Packages" />
  </config>

</configuration>

然后,作为测试结果,我可以在文件夹 ExternalReferences\Packages:

中获取包

希望对您有所帮助。