0
votes

I have a solution with 2 Class Library in C#.

enter image description here

I have a pipeline in Azure DevOps that build and publish one NuGet package and it is working. The YAML is

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- task: DotNetCoreCLI@2
  displayName: Restore packages
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
- task: DotNetCoreCLI@2
  displayName: Build project
  inputs:
    command: 'build'
    projects: '**/*.csproj'
- task: DotNetCoreCLI@2
  displayName: Run tests
  inputs:
    command: 'test'
    projects: '**/*[Te]ests/*.csproj'
- task: NuGetCommand@2
  displayName: Prepare the package
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'PackageVersion'
- task: NuGetCommand@2
  displayName: Push the package
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'xxx'

When I have 2 projects this pipeline failed. I noticed that in the build step, the projects are created in a Debug folder.

enter image description here

In the "Prepare the package" the pipeline is searching for the .dll in the Release folder in Azure DevOps.

enter image description here

Then, I have a few of questions:

  • is it possible to create and publish more than one package with the same pipeline?
  • I'm using Visual Studio 2021 and I haven't created any .nuspec. Do I have to create them?
  • Why does Azure DevOps use 2 different folders for build and package? Do I have to pass as argument a different folder?
1
Don't post screenshots of error messages. Especially not when it's red text on a black background. Lots of colorblind people (myself included) have tons of trouble reading red-on-black text.Daniel Mann

1 Answers

1
votes

So you should provide --configuration Release for your build step. Since you didn't provide it it consider Debug as default and pack consider Release as default.

variables:
  buildConfiguration: 'Release'

steps:
- task: DotNetCoreCLI@2
  displayName: Restore packages
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
    projects: '**/*.csproj'
  displayName: 'dotnet build $(buildConfiguration) --no-restore'

- task: DotNetCoreCLI@2
  inputs:
    command: test
    projects: '**/*[Te]ests/*.csproj'
    arguments: '--configuration $(buildConfiguration) --no-build'

- task: DotNetCoreCLI@2
  displayName: 'dotnet pack'
  inputs:
    command: 'pack'
    projects: '**/*.csproj'
    arguments: '-o $(Build.ArtifactStagingDirectory)/Output --no-build'
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'PackageVersion'
- task: DotNetCoreCLI@2
  displayName: "Publish packages"
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/Output/*.*nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'guid'

Answering your other questions:

is it possible to create and publish more than one package with the same pipeline?

Yes

I'm using Visual Studio 2021 and I haven't created any .nuspec. Do I have to create them?

No