Azure devops 构建管道似乎两次恢复 nuget 包
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.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5):
error NETSDK1047: Assets file
'D:\a\s\ServiceHosts\TestProject\obj\project.assets.json' doesn't
have a target for 'netcoreapp3.1/win-x64'. Ensure that restore has run
and that you have included 'netcoreapp3.1' in the TargetFrameworks for
your project. You may also need to include 'win-x64' in your project's
RuntimeIdentifiers.
通过向 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>
来自网络 documentation
You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.
The dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.
您应该在 dotnet publish
中使用 --no-restore
或删除 dotnet restore
并让 dotnet publish
隐式恢复包
我有一个构建管道,其中我有一个使用 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.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file 'D:\a\s\ServiceHosts\TestProject\obj\project.assets.json' doesn't have a target for 'netcoreapp3.1/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers.
通过向 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>
来自网络 documentation
You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.
The dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.
您应该在 dotnet publish
中使用 --no-restore
或删除 dotnet restore
并让 dotnet publish