Create a PublishProfile such as ghcr.pubxml
1<?xml version="1.0" encoding="utf-8"?>2<!--3https://go.microsoft.com/fwlink/?LinkID=208121.4-->5<Project>6 <PropertyGroup>7 <WebPublishMethod>Container</WebPublishMethod>8 <ContainerPublishMethod>NetSdk</ContainerPublishMethod>9 <ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:8.0</ContainerBaseImage>10 <ContainerRepository>YOURUSER/YOURPACKAGE</ContainerRepository>11 <RegistryUrl>ghcr.io</RegistryUrl>12 <UserName>YOURUSER</UserName>13 <PublishImageTag>latest</PublishImageTag>14 <PublishProvider>ContainerRegistry</PublishProvider>15 <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>16 <LastUsedPlatform>Any CPU</LastUsedPlatform>17 <RuntimeIdentifier>linux-x64</RuntimeIdentifier>18 <ProjectGuid>123d0968-84f9-4858-bd7a-df45893ea1f8</ProjectGuid>19 <_TargetId>NetSdkCustomContainerRegistry</_TargetId>20 <ExcludeApp_Data>false</ExcludeApp_Data>21 <TargetFramework>net8.0</TargetFramework>22 <SelfContained>true</SelfContained>23 </PropertyGroup>24</Project>
To build and push to registry, use: dotnet publish --os linux --arch x64 -c Release /p:PublishProfile=ghcr
dotnet publish --os linux --arch x64 -c Release /p:PublishProfile=ghcr