[英]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.