[Azure DevOps Series] Azure DevOps builds and releases Nuget package

Earlier I created a very simple class library. I will not go into too much description here. Next, we need to edit the csproj file. When we create the Nuget package, we will use the dotnet pack command. This is slightly different from the traditional Nuget CLI. In the traditional Nuget CLI, we create a nuspec file and run nuget pack against the nuspec. The dotnet pack command will create a nuspec file from csproj, and then pack the code into a nupkg file. Some key information needs to be added to the csproj file to ensure that it can create the Nuget package correctly. First we need a PackageId, which will be the name of the Nuget package itself. This name must be unique according to the location we want to publish. Next is Version, which will be the version number of the published package, as shown below. Our csproj file

netstandard2.0 AzureDevOpsTest.Common 1.0.0 HueiFeng Test project of common utils true

We need to create a project in Azure DevOps and bind the git repository. After binding, we first create the relevant service account information. The steps are as follows:

file

file

file

Build the project (dotnet build)

  • task: DotNetCoreCLI@2
    displayName: ‘dotnet build’
    inputs:
    command: ‘build’
    arguments: ‘–configuration $(buildConfiguration)’
    打包项目(dotnet pack)

Using nobuild means that the project will not be compiled before running pack because it has already been built in the steps above

  • task: DotNetCoreCLI@2
    displayName: “dotnet pack”
    inputs:
    command: ‘pack’
    arguments: ‘–configuration $(buildConfiguration)’
    packagesToPack: ‘**/*.csproj’
    nobuild: true
    versioningScheme: ‘off’

Publish project (nuget push)

As shown below, this method is suitable for the artifact library in the Azure DevOps organization. Of course, visibility can be set in the artifact library, and we can set the public and private of the package. allowPackageConflicts: true means that in the case of duplicate versions, you can skip duplicate versions and avoid returning 409. But this method cannot be used in Nuget.exe, which will inevitably affect the normality of our pipeline by returning 409. We can only choose to ignore and publish through dotnet nuget push, as written in the second code snippet below.

I have actually sought the answer to this question, but what the team gave here is:

I have discussed this with the team and we have decided not to add this functionality to the task. Instead of using these “bulkier” tasks we now recommend using the NuGet Authenticate task to authenticate to Azure DevOps Artifacts feeds and to use a script task with nuget/dotnet to use the parameters you need.
The reason for this is that the NuGet/Dotnet clients are actively being developed and new parameters and functionality are being added often. To keep up with all of the updates causes a lot of extra support for these bulky tasks. Please use example above to set up your pipeline with the ‘–skip-duplicate’ parameter. Thank you for understanding.
这是痛苦的这将代表我们无法通过如下这种很简单的方式不得不选择通过dotnet nuget push进行发布,不太清真了。。。

  • task: NuGetCommand@2
    inputs:
    command: ‘push’
    packagesToPush: ‘ ( B u i l d . A r t i f a c t S t a g i n g D i r e c t o r y ) / ∗ ∗ / ∗ . n u p k g ; ! (Build.ArtifactStagingDirectory)/**/*.nupkg;! (Build.ArtifactStagingDirectory)//.nupkg;!(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg’
    nuGetFeedType: ‘external’
    publishFeedCredentials: ‘hueifeng_nuget’
    allowPackageConflicts: true
  • task: DotNetCoreCLI@2
    displayName: “dotnet push”
    inputs:
    command: ‘custom’
    custom: ‘dotnet nuget push $(Build.ArtifactStagingDirectory)/**/*.nupkg -k $(APIKey) -s https://api.nuget.org/v3/index.json --skip-duplicate’
    Absorbing material: www.goodsmaterial.com

Guess you like

Origin blog.csdn.net/weixin_45032957/article/details/108444500