用于构建 .NET Framework Artifact 多个项目的 Azure DevOps 管道

问题描述 投票:0回答:1

我正在使用 Azure DevOps 构建和打包具有多个项目引用的 .NET csproj。虽然 MSBuild 任务成功编译了 csproj 并包含 bin\Release 目录中的所有引用的项目,但后续的 pack 任务不会在最终的 NuGet 包中包含这些引用的项目。

什么有效:

msbuild 命令正确编译解决方案,bin\Release 中的输出包含项目引用中的所有必需的 DLL。

什么不起作用:

带有 Pack 目标的 NuGetCommand@2 命令不包含生成的 NuGet 包中所有必需的项目引用。相反,仅包含主要项目的输出。

我尝试过的:

将 IncludeReferencedProjects=true 与 Pack 目标结合使用,理论上应包含 NuGet 包中引用的项目。 检查 csproj 文件以确保所有项目引用都正确,包括其路径。 Azure DevOps 管道中 MSBuild 任务的各种配置,包括内联 PowerShell 脚本和 YAML 任务定义。

我需要什么:

我需要 NuGetCommand@2 任务的 Pack 目标来包含项目引用中的 DLL,就像构建后出现在 bin\Release 文件夹中一样。

任何能够确保在使用 Azure DevOps 时所有引用的项目都包含在 NuGet 包中的见解或解决方案将不胜感激。


    - 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)'

更新答案请查看所附截图@wade Zhou

pipeline output screenshot

.net azure-devops yaml nuget nuget-package
1个回答
0
投票

根据 nuget pack 文档

请检查您的项目中是否有

project named
.nuspec
文件。如果文件存在,它将在 nuget pack 任务中调用它:

您可以:

  1. 暂时删除
    .nuspec
    文件,在nuget pack任务中使用
    includeReferencedProjects: true
    ,检查是否有效。我的管道结果供您参考:

  1. 或者如果您想保留
    .nuspec
    文件,请检查
    <files>
    (dll名称,路径...等)是否正确。
© www.soinside.com 2019 - 2024. All rights reserved.