.NET MAUI 项目未编译目标 android MSB4057:项目中不存在目标“UpdateGenerateFiles”

问题描述 投票:0回答:1

我正在构建一个 .NET MAUI 应用程序,在尝试构建和运行该应用程序时发现了此错误,但当我运行它附带的模板时它运行正常,但现在它给出了此错误:MSB4057:目标“UpdateGenerateFiles” ' 项目中不存在。

这是我的 MainPage.xaml 文件

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ToDoMAUIClient.MainPage">


</ContentPage>

这是我的项目.csproj

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

    <PropertyGroup>
        <TargetFrameworks>net6.0-android</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
        <OutputType>Exe</OutputType>
        <RootNamespace>ToDoMAUIClient</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>

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

        <!-- App Identifier -->
        <ApplicationId>com.companyname.todomauiclient</ApplicationId>
        <ApplicationIdGuid>d0e774d6-0ec2-4307-8314-b664a5b61b51</ApplicationIdGuid>

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

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

        <!-- 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>
      <None Remove="Platforms\Android\Resources\xml\network_security_config.xml" />
    </ItemGroup>

</Project>

我尝试查找此错误 MSB4057,它说它与拼写错误或未找到的资源路径有关,即使在 microsoft 错误参考上也有说明,但我找不到资源“UpdateGenerateFiles”或单击时使用它的位置错误 Visual Studio 将我引导到 csproj 文件的第一行。

c# android xaml maui csproj
1个回答
0
投票

您的项目确实没有

UpdateGeneratedFiles
目标。您可以将目标添加到 .csproj 文件中。

 <Target Name="UpdateGeneratedFiles" BeforeTargets="BeforeBuild;BeforeRebuild" DependsOnTargets="NSwag">
    <ItemGroup>
      <Compile Include="Gen\MyClient.cs" Condition="!Exists('Gen\MyClient.cs')" />
    </ItemGroup>
 </Target>
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.