LoginSignup
0
1

More than 3 years have passed since last update.

DotNetCoreCLI@2でprojectsに指定した値と違うプロジェクトがpublishされる

Last updated at Posted at 2020-04-29

Azure DevOpsのPipelinesでDotNetCoreCLI@2で指定したつもりのソリューションがpublishされず、かなり時間を浪費したため、状況をまとめます。

全く違うプロジェクトがビルドされていた

こんな風にGitリポジトリには複数プロジェクトが存在し、共通のクラスライブラリを見ています。
AのslnファイルにはCoreとAだけ、BのslnファイルにはCoreとBだけが含まれている状態です。

フォルダ構成
├ HogeHoge.Core (.Net Coreクラスライブラリ)
│  └ HogeHoge.Core.csproj
├ HogeHoge.A.Functions (Azure FunctionsプロジェクトA)
│  └ HogeHoge.A.Functions.csproj
├ HogeHoge.B.Functions (Azure FunctionsプロジェクトB)
│  └ HogeHoge.B.Functions.csproj
├ HogeHoge.A.Functions.sln
├ HogeHoge.B.Functions.sln

PipelineのYMLでは最初はこんな風に指定していました。(変数の指定については割愛)

最初に作ったYML
    - task: DotNetCoreCLI@2
      inputs:
        command: 'publish'
        projects: '**/HogeHoge.B.Functions.sln'
        arguments: '--configuration $(buildConfiguration) -r $(buildPlatform) --output $(Build.ArtifactStagingDirectory)'
        zipAfterPublish: true

Publishは成功しているのですが、何故かAのFunctionsがPublishされています。
Pipelineのログを見ると、何故かAプロジェクトが直接参照されています。
何故projectsの指定が無視されるのか・・・

==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.167.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\windows\system32\chcp.com 65001
Active code page: 65001
C:\hostedtoolcache\windows\dotnet\dotnet.exe publish d:\a\1\s\HogeHoge.A.Functions\HogeHoge.A.Functions.csproj --configuration Release -r win-x64 --output d:\a\1\a\HogeHoge.A.Functions

その1:Projectsの記法が異なる

まず、projectsの指定方法が間違っていました。こんな風に書かないと認識されません。

        projects: |
         **/HogeHoge.B.Functions.sln

その2: publishWebProjectsが必要

publishWebProjectsをfalseであっても指定しないとprojectsの指定は無視されるようです。
projectsの指定がない場合、勝手に適当なプロジェクトを探しに行ってしまうらしい。だったらエラーを吐いてほしい・・・

        publishWebProjects: false # このパラメータが無いとprojectsの指定が無視される

結果

こんなYMLに変更することで、ちゃんとpublishされるようになりました。

    - task: DotNetCoreCLI@2
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: |
         **/HogeHoge.B.Functions.sln
        arguments: '--configuration $(buildConfiguration) -r $(buildPlatform) --output $(Build.ArtifactStagingDirectory)'
        zipAfterPublish: true

参考

DotNetCoreCLI@2 ignores projects on publish
https://developercommunity.visualstudio.com/content/problem/826169/dotnetcorecli-3.html
Excluding projects when executing the DotNetCoreCLI@2 task
https://stackoverflow.com/questions/58975756/excluding-projects-when-executing-the-dotnetcorecli2-task

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1