sdk-container-builds icon indicating copy to clipboard operation
sdk-container-builds copied to clipboard

Cannot specify ContainerEnvironmentVariable via the command line using -p:ContainerEnvironmentVariable=?

Open lymberl opened this issue 2 years ago • 7 comments

For automating builds and deploys it would be useful if we can specify container environment variables via the command line. Such as: dotnet publish --os linux --arch x64 -p:ContainerEnvironmentVariable=EnvironmentVariable=Value /t:PublishContainer -c Release

How can this be done via the command line since that property is a complex property? <ContainerEnvironmentVariable Include="ASPNETCORE_ENVIRONMENT" Value="Development" />

But when building for other environments i would like to set it to a different value such as the below: <ContainerEnvironmentVariable Include="ASPNETCORE_ENVIRONMENT" Value="Staging" />

Are there any workarounds or other means to achieve this?

lymberl avatar May 31 '23 07:05 lymberl

Hi @lymberl - currently this is not possible. MSBuild doesn't allow passing Items on the command line. @rainersigwald are there patterns that we could rely on here? Or I suppose in the worst case we could do something like

  • have a property that users could set
  • have a target that explicitly 'splits' that property into Items by parsing a specific format.

baronfel avatar May 31 '23 14:05 baronfel

  • have a property that users could set
  • have a target that explicitly 'splits' that property into Items by parsing a specific format.

This is the best I can think of too; it's nice and explicit.

rainersigwald avatar Jul 26 '23 19:07 rainersigwald

How confusing would it be if we chose the Property name of ContainerEnvironmentVariable as well? Does MSBuild handle the ambiguity correctly based on how the name is used, either in @() for items or $() for Properties?

Otherwise I suppose that would impact the choice of name for the property to use here.

baronfel avatar Jul 26 '23 19:07 baronfel

Yes, we have totally separate lookup tables so you can have a property and an item with the same name. It tends to be pretty confusing to debug (even more than getting it wrong when there's only one but it's the other kind) but in this case I think that's outweighed by the consistency of naming.

rainersigwald avatar Jul 26 '23 20:07 rainersigwald

We need something like this for CI/CD, as is we need to stick to docker based container builds to inject environment variables.

almostjulian avatar Apr 12 '24 19:04 almostjulian

Is it resolved?, we are facing the same issue on providing ContainerEnvironmentVariable in the command line to set ASPNETCORE_ENVIRONMENT Environment variable.

SViradiya-MarutiTech avatar Nov 13 '24 06:11 SViradiya-MarutiTech