You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI Blazor Hybrid发布报错MSB4057:目标“_GenerateAppxPackage”不存在

解决.NET MAUI Blazor Hybrid发布时_GenerateAppxPackage目标不存在的问题

问题描述

使用Visual Studio 2022最新版发布仅支持Windows平台的.NET MAUI Blazor Hybrid应用时,出现错误:

The target "_GenerateAppxPackage" does not exist in the project.

应用本地运行正常,已尝试更换.NET构建版本、更新VS、清理解决方案等操作,问题仍存在,目标是发布到Microsoft Store。项目csproj配置如下:

<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>

解决方案

1. 添加Windows App SDK支持配置

在项目的主<PropertyGroup>节点中添加以下属性,确保启用Windows应用打包相关的MSBuild目标:

<UseWindowsAppSDK>true</UseWindowsAppSDK>
<WindowsPackageType>MSIX</WindowsPackageType>

2. 选择正确的发布目标类型

发布时必须选择Windows App Package作为发布目标,而非Folder或其他选项:

  • 右键项目 → 发布
  • 创建新配置文件,选择"Windows App Package"
  • 按向导关联Microsoft Store开发者账号,完成配置后再尝试发布

3. 添加Windows SDK构建工具包引用

在<ItemGroup>节点中添加兼容.NET 8的Windows SDK构建工具包引用:

<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="8.0.23.53103" PrivateAssets="all" />

该包包含生成Appx/MSIX包所需的核心MSBuild目标文件。

4. 修正ApplicationId格式(可选)

Microsoft Store要求ApplicationId遵循PublisherName.AppName格式,建议将当前的com.thesecurity.saveit修改为与开发者账号匹配的格式(如TheSecurity.SaveIt),避免发布时触发额外验证错误。

5. 重新生成项目

完成上述修改后:

  • 清理解决方案:菜单 → 项目 → 清理解决方案
  • 重启Visual Studio
  • 重新生成项目后再执行发布操作

内容的提问来源于stack exchange,提问作者TheSecurity

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 05:18:12