dotnet / sdk-container-builds

Libraries and build tooling to create container images from .NET projects using MSBuild
https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
MIT License
175 stars 30 forks source link

Unable to use the ContainerRegistry as parameter on dotnet publish #565

Closed Depechie closed 2 months ago

Depechie commented 2 months ago

When using the DotNetCoreCLI@2 task in a Azure Devops pipeline, I can do a dotnet publish straight to my private Azure Container registry if I put the registry name as a property in the csproj file like:

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <ContainerRegistry>myawesomedummyname.azurecr.io</ContainerRegistry>
  </PropertyGroup>

But trying to move this to a command parameter like so:

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: 'publish'
    projects: './src/ACAObservability.Web/ACAObservability.Web.csproj'
    arguments: >-
      -p:PublishProfile="DefaultContainer"
      -p:PublishSingleFile="true"
      -p:PublishTrimmed="false"
      --self-contained "true"
      --verbosity "quiet"
      --nologo
      -r "linux-amd64"
      -p:ContainerRepository="acaobservability.web"
      -p ContainerImageTags="\"$(dockerImageTag);latest\""
      -p:ContainerRegistry="myawesomedummyname.azurecr.io"'

I see in the build log, that the task obfuscates the registry name to But it will also fail with the exception: `error CONTAINER2012: Could not recognize registry ''`

baronfel commented 2 months ago

So you're saying that the AzDo task has mutated the registry URL?

Depechie commented 2 months ago

The build task logs the actual constructed publish command and it reads like so:

/usr/bin/dotnet publish /home/vsts/work/1/s/./src/ACAObservability.Web/ACAObservability.Web.csproj -p:PublishProfile=DefaultContainer -p:PublishSingleFile=true -p:PublishTrimmed=false --self-contained true --verbosity quiet --nologo -r linux-amd64 -p:ContainerRepository=acaobservability.web -p ContainerImageTags="187;latest" -p:ContainerRegistry=***'

Not sure 'who' does the obfuscation or mutation, but yeah that is what I notice indeed.

chrisoverzero commented 2 months ago

This may seem like a silly question, but could this be due to the stray single quote after the argument?

-p:ContainerRegistry="myawesomedummyname.azurecr.io"'

It shows up in the build task logs, too:

-p:ContainerRegistry=***'
baronfel commented 2 months ago

That's an excellent idea @chrisoverzero.

One way we could find out for sure is with a binlog - one of the first lines in the binlog viewer is the complete MSBuild command line as seen by the engine.

Depechie commented 2 months ago

Totally not a silly question!! Was a copy paste error :( the actual yaml file does not have that.

Depechie commented 2 months ago

Hmmm now that you mention it, the composed logs has indeed the '

Let me change the yaml again and retest.

I will get back with more info.

Depechie commented 2 months ago

Ok sorry for the inconvenience... I indeed had a rogue ' ( checked the GIT log ). And without it, everything works perfectly!

baronfel commented 2 months ago

Glad to hear it @Depechie!