ContainerEnvironmentVariable Supported in Latest VS2022 17.8.5?

Ben Brandt 51 Reputation points
2024-01-17T20:10:20.13+00:00

https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container?pivots=dotnet-8-0#containerenvironmentvariable I have an ASP.NET Core project that I am using to publish to an Azure Container registry with dotnet publish. I tried adding the ContainerEnvironmentVariable, but am getting this error:

C:\src\path-to-project\Project.Api.csproj : error  : The attribute "Include" in element <ContainerEnvironmentVariable> is unrecognized.

My VS version:

Microsoft Visual Studio Professional 2022
Version 17.8.5
VisualStudio.17.Release/17.8.5+34511.84
Microsoft .NET Framework
Version 4.8.09032
Installed Version: Professional
ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools
ASA Service Provider   1.0
ASP.NET and Web Tools   17.8.358.6298
ASP.NET and Web Tools
Azure App Service Tools v3.0.0   17.8.358.6298
Azure App Service Tools v3.0.0
Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools   17.8.358.6298
Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio
C# Tools   4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
CreateUnitTestBoilerplateCommand Extension   1.0
CreateUnitTestBoilerplateCommand Visual Studio Extension Detailed Info
Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query
Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics
Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects
Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
NuGet Package Manager   6.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Razor (ASP.NET Core)   17.8.3.2405201+d135dd8d2ec1c2fbdee220e8656b308694e17a4b
Provides languages services for ASP.NET Core Razor.
SQL Server Data Tools   17.8.120.1
Microsoft SQL Server Data Tools
ToolWindowHostedEditor   1.0
Hosting json editor into a tool window
TypeScript Tools   17.0.20920.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools   4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools   17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50
Microsoft Visual F# Tools
Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,460 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,502 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,272 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 18,325 Reputation points Microsoft Employee
    2024-01-18T03:06:17.6733333+00:00

    @Ben Brandt Welcome to Microsoft Q&A Forum, Thank you for posting your query here! I'm glad to see you were able to resolve your issue. Thanks for posting your solution so that others experiencing the same thing can easily reference this. Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer, they can only accept answers by others, I'll repost your solution in case you'd like to Accept the answer.
    .
    Issue:

    You have an ASP.NET Core project that you are trying to publish to an Azure Container registry with dotnet publish. You are getting this error:

    C:\src\path-to-project\Project.Api.csproj : error : The attribute "Include" in element <ContainerEnvironmentVariable> is unrecognized.
    .
    Resolution:
    The container environment variable node allows you to add environment variables to the container. Environment variables are accessible to the app running in the container immediately, and are often used to change the run-time behavior of the running app.

    The ContainerEnvironmentVariable node has two attributes:

    • Include: The name of the environment variable.
    • Value: The value of the environment variable.
    <ItemGroup>
      <ContainerEnvironmentVariable Include="LOGGER_VERBOSITY" Value="Trace" />
    </ItemGroup>
    
    

    So it should be an ItemGroup and not a PropertyGroup. More info here.

    1 person found this answer helpful.
    0 comments No comments