[英]Azure devops build pipeline seems to restore nuget packages twice
我有一个构建管道,其中我有一个使用 NuGetCommand 的 Nuget 恢复步骤,它工作正常。
但是由于缺少 nuget 包,执行构建的下一步会失败。
似乎构建步骤试图第二次恢复 nuget 包,这不起作用(它没有这样做的凭据)
构建定义的 yaml 文件如下:
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: CopyFiles@2
displayName: 'copy sql scripts'
inputs:
SourceFolder: 'Resources/TestProject/Migrations/Sql'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)/SqlScripts'
- task: NuGetCommand@2
displayName: 'NuGet Restore'
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: './nuGet.config'
externalFeedCredentials: 'TelerikFeed'
- task: DotNetCoreCLI@2
displayName: 'Build ServiceHost projects'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/ServiceHosts/**/*.csproj'
arguments: '-c Release -r win-x64 --self-contained false -o $(Build.ArtifactStagingDirectory) /p:SourceRevisionId=$(Build.SourceVersion)'
zipAfterPublish: false
- task: PublishBuildArtifacts@1
displayName: 'Publish artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
我还有一个 nuGet.config 文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- remove any machine-wide sources with <clear/> -->
<clear />
<add key="MyFeed" value="https://pkgs.dev.azure.com/MyCompany/_packaging/NugetFeed/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Telerik_NuGet" value="https://nuget.telerik.com/nuget" />
</packageSources>
</configuration>
我不明白为什么构建步骤需要再次恢复 nuget 包。
有没有办法将 DotNetCoreCli 指向已经恢复的包?
编辑:
正如@Ibrahim 所建议的,我将 --no-restore 添加到 DotNetCoreCLI 任务中。 然后我收到以下错误消息:
C:\Program Files\dotnet\sdk\5.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file 'D:\a\1\s\ ServiceHosts\TestProject\obj\project.assets.json' 没有 'netcoreapp3.1/win-x64' 的目标。 确保恢复已运行,并且您已在项目的 TargetFrameworks 中包含“netcoreapp3.1”。 您可能还需要在项目的 RuntimeIdentifiers 中包含“win-x64”。
通过向 yaml 文件添加任务以安装最新版本的 nuget 使用
- task: NuGetToolInstaller@1
inputs:
versionSpec: 5.9.1
并将 RuntimeIdentifier win-x64 添加到 csproj 文件中。
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>TestProject</AssemblyName>
<RootNamespace>TestProject</RootNamespace>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
来自 dotnet 文档
您不必运行 dotnet restore,因为它由所有需要还原的命令隐式运行,例如 dotnet new、dotnet build、dotnet run、dotnet test、dotnet publish 和 dotnet pack。 要禁用隐式还原,请使用 --no-restore 选项。
dotnet restore 命令在显式还原有意义的某些场景中仍然有用,例如 Azure DevOps 服务中的持续集成构建或需要显式控制何时发生还原的构建系统。
您应该在dotnet publish
中使用--no-restore
或删除dotnet restore
并让包由dotnet publish
隐式还原
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.