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
181 stars 39 forks source link

Unable to publish console app as container #551

Closed atrakic closed 9 months ago

atrakic commented 9 months ago

Ref: https://github.com/dotnet/sdk-container-builds/blob/main/docs/ZeroToContainer.md

$ dotnet --version
8.0.101

Create new console project and try to publish as container

$ dotnet new console -o ConsoleContainerExample
$ cd ConsoleContainerExample
$ dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  ConsoleContainerExample -> /Users/xx/src/xx/Drafts/ConsoleContainerExample/bin/Release/net8.0/linux-x64/ConsoleContainerExample.dll
/usr/local/share/dotnet/sdk/8.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(204,5): warning NETSDK1198: A publish profile with the name 'DefaultContainer' was not found in the project. Set the PublishProfile property to a valid file name. [/Users/xx/src/xx/Drafts/ConsoleContainerExample/ConsoleContainerExample.csproj]
  ConsoleContainerExample -> /Users/xx/src/xx/Drafts/ConsoleContainerExample/bin/Release/net8.0/linux-x64/publish/
baronfel commented 9 months ago

For console apps on 8.0.1xx you'll need to add the NuGet package. That 'Zero To Container' page assumes you have the package installed.

For 8.0.200, you can just add <EnableSdkContainerSupport>true</EnableSdkContainerSupport> and this will work.