在 Azure DevOps 管道中包含本地 dll

And*_*era 10 c# azure-devops azure-pipelines

在我的 C# 项目中,我引用了我公司的一个 DLL,该 DLL 不在 NuGet 上(因为它不是公开的),而我在 Azure DevOps 中的管道不断失败,因为它表示找不到引用。

Error CS0234: The type or namespace name 'YYY' does not exist in the namespace 'ZZZ' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

按照这篇文章的建议,我在解决方案中复制了该 dll,并从那里引用它,因此该 dll 受到版本控制并存在于存储库中。这是 csproj 的摘录:

<Reference Include="ZZZ.YYY, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\PrivateReferences\ZZZ.YYY.dll</HintPath>
  <Private>False</Private>
</Reference>
Run Code Online (Sandbox Code Playgroud)

该解决方案在我的机器上完美构建,但在 Azure 上却一直失败。我缺少什么?

谢谢!

在 Bright Ran-MSFT 回复后进行编辑
以下是我的 yaml 中的摘录:

trigger:
- develop

pool: 'Default'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
    vstsFeed: '<GUID of my Feed>'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)

Bri*_*SFT 8

您可以将这些 DLL 作为您自己的自定义 NuGet 包发布到Azure DevOps 上的Azure Artifacts源。然后,在项目的管道中,您可以使用NuGet 恢复任务将包恢复到项目中。

发布包后,在本地计算机上通过 Visual Studio 构建项目时,还可以连接到 Azure Artifacts 源以将包还原到项目中。

[更新]

您是否检查了管道运行的输出控制台日志以了解导致包无法恢复的原因?原因是否是未经授权的错误,例如401403

如果是这样,在 执行 NuGet 还原任务之前,您需要使用NuGet Authenticate 任务来提供身份验证信息。这里还需要创建一个NuGet服务连接以供使用。

通常,您设置的用于发布自定义包的 feed 是私有的,当访问管道中的 feed 时,需要进行身份验证。

在本地 Visual Studio 上,由于您已使用您的帐户登录,因此当您连接到 feed 时,VS 将自动使用您的帐户进行身份验证。