0

I am trying to replicate the following Azure pipeline using the CLI dotnet command:

- task: DotNetCoreCLI@2
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

So far, I can make the project build, but getting a zip file out of it seems problematic - passing the inputs zipAfterPublish etc appears impossible to pass, although, there is some scattered documentation suggesting these can be passed with -p:"optiona=x;optionb=y" or /p:"optiona=x;optionb=y". I can find no definitive documentation on this.

This is what I have - the build part works, the $PWD/out directory is populated with many files but nothing is zipped:

dotnet publish --configuration Release --output $PWD/out /p:"zipAfterPublish=true;publishWebProjects=true"

I'm guessing this is around how to pass the inputs ( https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops ) correctly to the command.

Jepper
  • 1,092
  • 3
  • 11
  • 24
  • I'm aware of this https://stackoverflow.com/questions/51485427/how-to-pass-build-properties-to-dotnet - it does not solve the problem – Jepper Mar 23 '20 at 12:54
  • The OS is Linux, sorry if this wasn't clear folks. – Jepper Mar 24 '20 at 09:26
  • Hi Jepper, any update for this issue? As I know dotnet command can't directly generate the publish package when the OS is in Linux. Maybe you need to consider other directions... – LoLance Mar 25 '20 at 08:32

1 Answers1

2

I am trying to replicate the following Azure pipeline using the CLI dotnet command:

1.The zipAfterPublish is one option available only in Dotnet Publish task. If you check the log of dotnet publish task, you'll find it doesn't pass any property like zipAfterPublish to the command:

enter image description here

Since only the msbuild property can be passed in this way: /p:xxx=xxx. The zipAfterPublish won't work in command-line as it's not msbuild property, that option is not supported in dotnet cli, only available in Azure Devops Dotnet Publish task.

2.Normally if we want to publish one .net core web project and zip it after publish using dotnet cli locally, we can use command like:

dotnet publish xx.csproj /nologo /p:PublishProfile=xxx /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform=xxx /p:configuration=xxx /p:DesktopBuildPackageLocation=SomePath\xxx.zip

Or

dotnet build xxx.sln /nologo /p:PublishProfile=Release /p:PackageLocation="C:\Some\Path\package" /p:OutDir="C:\Some\Path\out" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform="Any CPU" /p:configuration="Release" /p:DesktopBuildPackageLocation="C:\Some\Path\package\package.zip"

Which is described in this issue.

Above commands can work in windows to generate a xx.zip folder.

However:

It seems that you're in linux environment, please check this document. If you want to zip the publish folder(generate a package), the dotnet build/publish will call msdeploy.exe to do this job, but since MSDeploy lacks cross-platform support, the following MSDeploy options are supported only on Windows. So dotnet cli command is not supported to generate zip after publish in linux environment... What you want is not supported for now in Linux.

Possible workaround:

Since we can use dotnet publish to publish the project to one folder(Folder works cross-platform), we can call another zip command after dotnet publish to zip it ourselves.

Hope my answer helps to resolve your puzzle :)

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Good answer, now I understand. I eventually worked out how to inject the PATH environment variables required for the Azure build agent running on Linux (by adding to runsvc.sh which is run by systemd when the service starts), so that it could see binaries required to complete the build. Avoiding using the Linux native dotnet binary, allowed me to use the pipeline in the original question as is. Still on Linux. – Jepper Mar 28 '20 at 08:50