NuGet 如何决定将包目录放在哪里?

Owe*_*enP 5 nuget xamarin.forms azure-devops azure-pipelines

我正在处理少数 Xamarin Forms 项目和生成多目标 Xamarin 包的项目。我花了一天的时间努力让其中一个项目在 Azure DevOps 中正常运行,但我放弃了。

当我在本地处理一个特定的单元测试项目时,它会设置以下目录结构:

+ ProjectName
    + bin
    + obj
    + ...
+ packages
    + <nuget packages here>
Run Code Online (Sandbox Code Playgroud)

这种结构在项目文件的部分中表现出来,如下所示:

  <Import Project="..\..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" />
  <Import Project="..\..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.12.0\build\NUnit.props')" />
Run Code Online (Sandbox Code Playgroud)

项目文件的另一部分取决于此:

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
    <Error Condition="!Exists('..\..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props'))" />
  </Target>
Run Code Online (Sandbox Code Playgroud)

当我在本地构建它时,一切都很好。项目建立。测试通过。当我在 Azure DevOps 中构建它时,它失败了:

(EnsureNuGetPackageBuildImports target) -> 
  D:\a\1\s\[Redacted].Unit.Tests\[Redacted].Unit.Tests.csproj(97,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\..\packages\NUnit.3.12.0\build\NUnit.props.
Run Code Online (Sandbox Code Playgroud)

很明显,Azure DevOps 对packages文件夹的创建位置有不同的想法。如果我编辑..\..to ..\,一切正常。这与很多项目是一致的。在我的其他几个项目中,所有 .csproj 文件都使用..\并且它们具有以下目录结构:

+ ProjectName
    + bin
    + obj
    + packages
    + ...
Run Code Online (Sandbox Code Playgroud)

我在其中.csproj任何一个中都找不到任何似乎表明任何一个都在指示 nuget 以不同方式做任何事情的内容。但每个人的表现都大不相同。我唯一的猜测是我有一些超级隐藏的本地配置,用于更改默认行为的“损坏”配置,并且该文件不在源代码管理中,因此 DevOps 使用“真实”默认值?

什么可能导致这种情况发生?

有些人要求 .yml 以了解我们如何恢复软件包:我相信就是这样:

  - task: NuGetToolInstaller@1
    displayName: "Install nuget"
    inputs:
      versionSpec: '4.4.1'

  - task: NuGetCommand@2
    displayName: 'restore $(solution)'
    inputs:
      restoreSolution: '$(solution)'
      vstsFeed: "$(packageFeedName)"
Run Code Online (Sandbox Code Playgroud)

我不是DEVOPS家伙的球队,但我知道一点关于YML。$(solution)只是我们解决方案文件的路径,包提要名称就是它所说的。他们对我来说似乎很简单。