Azure Devops pipeline to build .NET Framework Artifact multiple projects

80 views Asked by At

I am using Azure DevOps to build and package a .NET csproj with multiple project references. While the MSBuild task successfully compiles the csproj and includes all referenced projects in the bin\Release directory, the subsequent pack task does not include these referenced projects in the final NuGet package.

What works:

The msbuild command compiles the solution correctly, and the output in bin\Release contains all the necessary DLLs from the project references.

What doesn't work:

The NuGetCommand@2 command with the Pack target does not include all the necessary project references in the resulting NuGet package. Instead, only the output of the primary project is included.

What I've tried:

Using IncludeReferencedProjects=true with the Pack target, which should theoretically include the referenced projects in the NuGet package. Inspecting the csproj files to ensure all project references are correct includint their paths. Various configurations of the MSBuild task in Azure DevOps pipelines, including inline PowerShell scripts and YAML task definitions.

What I need:

I need the Pack target of the NuGetCommand@2 task to include the DLLs from the project references just as it appears in the bin\Release folder after a build.

Any insights or solutions to ensure that all referenced projects are included in the NuGet package when using Azure DevOps would be greatly appreciated.


    - task: NuGetCommand@2
       inputs:
         restoreSolution: '$(MainCsprojFile)'
       displayName: 'Restore NuGet Packages'
   
     - task: MSBuild@1
       inputs:
         solution: '$(MainCsprojFile)'
         platform: '$(buildPlatform)'
         configuration: '$(buildConfiguration)'
       displayName: 'Build with MSBuild'
   
     - task: NuGetCommand@2
       displayName: 'Pack NuGet package'
       inputs:
         command: 'pack'
         packagesToPack: '$(MainCsprojFile)'
         versioningScheme: 'off'
         versionEnvVar: 'PackageVersion'
         includeReferencedProjects: true
         outputDir: '$(Build.ArtifactStagingDirectory)'

UPDATE ANSWERING please check the screenshot attached @wade zhou

pipeline output screenshot

1

There are 1 answers

6
wade zhou - MSFT On

As per the nuget pack doc:

enter image description here

Please check if you have project named .nuspec file on your project. If the file exists, it will invoke it in the nuget pack task:

enter image description here

You can:

  1. temporarily remove the .nuspec file, with includeReferencedProjects: true in nuget pack task, check if it works. My pipeline result for your reference:

enter image description here

  1. Or if you would like to keep the .nuspec file, please check if the <files>(dll name, path...etc) is correct. enter image description here