Search code examples
visual-studiomaui

MAUI Publish error - MSB4057: The target "_GenerateAppxPackage" does not exist in the project


whenever i try to publish my .NET MAUI Blazor Hybrid appliation using Visual Studio 2022 latest version I am getting error The target "_GenerateAppxPackage" does not exist in the project.. Locally it is runnig great.

I removed support for all the other platforms but Windows.

My csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk.Razor">

    <PropertyGroup>
        <TargetFrameworks>net8.0-windows10.0.19041.0</TargetFrameworks>

        <OutputType>Exe</OutputType>
        <RootNamespace>SaveIt.App.UI</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
        <EnableDefaultCssItems>false</EnableDefaultCssItems>
        <Nullable>enable</Nullable>

        <!-- Display name -->
        <ApplicationTitle>SaveIT</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.thesecurity.saveit</ApplicationId>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        
      <GenerateAppInstallerFile>False</GenerateAppInstallerFile>
        <AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
        <AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
        <AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
        <GenerateTestArtifacts>True</GenerateTestArtifacts>
        <GenerateTemporaryStoreCertificate>True</GenerateTemporaryStoreCertificate>
        <HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
        <AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
        <PackageCertificateThumbprint>XXXXXXXXXXX</PackageCertificateThumbprint>
    </PropertyGroup>

    <PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(Configuration)' == 'Release'">
      <AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>
      <PackageCertificateThumbprint>XXXXXXXXXXX</PackageCertificateThumbprint>
    </PropertyGroup>
      <PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(RuntimeIdentifierOverride)' != ''">
      <RuntimeIdentifier>$(RuntimeIdentifierOverride)</RuntimeIdentifier>
    </PropertyGroup>

  <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\saveit_icon.svg" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />

        <!-- Custom Fonts -->
        <MauiFont Include="Resources\Fonts\*" />

        <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

    <ItemGroup>
      <EmbeddedResource Include="appsettings.Development.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <DependentUpon>appsettings.json</DependentUpon>
      </EmbeddedResource>
      <EmbeddedResource Include="appsettings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </EmbeddedResource>
      <EmbeddedResource Include="appsettings.Production.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <DependentUpon>appsettings.json</DependentUpon>
      </EmbeddedResource>
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Blazor.Bootstrap" Version="2.2.1" />
        <PackageReference Include="Blazored.FluentValidation" Version="2.2.0" />
        <PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.6" />
        <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.60" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.60" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.60" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\SaveIt.App.Infrastructure\SaveIt.App.Infrastructure.csproj" />
      <ProjectReference Include="..\SaveIt.App.Persistence\SaveIt.App.Persistence.csproj" />
    </ItemGroup>

</Project>

I tried changing .NET build versions, updating Visual Studio, removing .vs folder and cleaning the solution.

Excpected result is that I am able to publish my application to Microsoft Store


Solution

  • You can try to use the command dotnet publish directly.

    For example:

    dotnet publish -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64
    

    For more information, please check document: Publish a packaged .NET MAUI app for Windows with the CLI.