Microsoft.PackageDependencyResolution.targets(266,5):错误NETSDK1005:资产文件“obj\project.assets.json”没有“net8.0”的目标

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

我有一个简单的 C# 项目,包含以下 .csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">
    
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> 

        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <PropertyGroup>
        <EnableDefaultCompileItems>true</EnableDefaultCompileItems>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="CrcDotNET" Version="1.0.3" />
        <PackageReference Include="System.IO.Ports" Version="8.0.0" />
        <PackageReference Include="System.Threading.Tasks" Version="4.3.0" />
    </ItemGroup>
</Project>

当我尝试使用“dotnet build Foo.csproj”在 localdev 上构建它时,一切都可以正常工作。但是当我在 Azure 上使用相同的命令时,我收到以下神秘错误:

2024-02-22T12:23:29.8030466Z ##[section]Starting: Build and Pack 'Laeerdal.Usb.csproj'
2024-02-22T12:23:29.8150494Z ==============================================================================
2024-02-22T12:23:29.8151277Z Task         : .NET Core
2024-02-22T12:23:29.8151536Z Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2024-02-22T12:23:29.8151870Z Version      : 2.235.0
2024-02-22T12:23:29.8152112Z Author       : Microsoft Corporation
2024-02-22T12:23:29.8152370Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2024-02-22T12:23:29.8152667Z ==============================================================================
2024-02-22T12:23:30.2857118Z [command]C:\Windows\system32\chcp.com 65001
2024-02-22T12:23:30.2964423Z Active code page: 65001
2024-02-22T12:23:30.3088676Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2024-02-22T12:23:30.3142054Z [command]"C:\Program Files\dotnet\dotnet.exe" build D:\a\1\s\Foo\Foo.csproj "-dl:CentralLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.235.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" /restore /p:PackageOutputPath=D:\a\1\a /p:JavaSdkDirectory=C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.402-6\x64/ /p:VersionMajor=1 /p:VersionMinor=30 /p:VersionPatch=2 /p:VersionRevision=50224 /p:VersionSuffix=
2024-02-22T12:23:30.4882178Z MSBuild version 17.9.4+90725d08d for .NET
2024-02-22T12:23:31.3250928Z   Determining projects to restore...
2024-02-22T12:23:31.5489970Z ##[warning]C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): Warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file.
2024-02-22T12:23:31.5529575Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0]
2024-02-22T12:23:31.6426560Z ##[warning]C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): Warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file.
2024-02-22T12:23:31.6431641Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0-windows10.0.19041.0]
2024-02-22T12:23:32.5074255Z   Restored D:\a\1\s\Foo\Foo.csproj (in 702 ms).
2024-02-22T12:23:37.4168585Z ##[warning]C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): Warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file.
2024-02-22T12:23:37.4173672Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0]
2024-02-22T12:23:37.6003354Z ##[error]C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: Assets file 'D:\a\1\s\Foo\obj\project.assets.json' doesn't have a target for 'net8.0'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project.
2024-02-22T12:23:37.6025309Z C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'D:\a\1\s\Foo\obj\project.assets.json' doesn't have a target for 'net8.0'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0]
2024-02-22T12:23:37.9060631Z 
2024-02-22T12:23:37.9092458Z Build FAILED.
2024-02-22T12:23:37.9172096Z 
2024-02-22T12:23:37.9242343Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0]
2024-02-22T12:23:37.9327192Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0-windows10.0.19041.0]
2024-02-22T12:23:37.9343030Z C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\8.0.6\Sdk\BundledVersions.targets(85,5): warning MA002: Starting with .NET 8, setting  <UseMaui>true</UseMaui>  does not automatically include NuGet package references in your project.  Update your project by including this item:  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />.  You can skip this warning by setting  <SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>  in your project file. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0]
2024-02-22T12:23:37.9348329Z C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'D:\a\1\s\Foo\obj\project.assets.json' doesn't have a target for 'net8.0'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project. [D:\a\1\s\Foo\Foo.csproj::TargetFramework=net8.0]
2024-02-22T12:23:37.9349813Z     3 Warning(s)
2024-02-22T12:23:37.9350763Z     1 Error(s)
2024-02-22T12:23:37.9352937Z 
2024-02-22T12:23:37.9385231Z Time Elapsed 00:00:07.20
2024-02-22T12:23:39.2936283Z ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
2024-02-22T12:23:39.2939954Z ##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
2024-02-22T12:23:39.2961848Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2024-02-22T12:23:39.2963921Z ##[error]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\\a\\1\\s\\Foo\\Foo.csproj' ]
2024-02-22T12:23:39.3057978Z ##[section]Finishing: Build and Pack 'Laeerdal.Usb.csproj'
c# .net msbuild azure-pipelines nuget
1个回答
0
投票

(并回答我自己的问题...)错误是我正在使用:

<TargetFramework>net8.0</TargetFramework>

虽然我应该使用:

<TargetFrameworks>net8.0</TargetFrameworks>

构建在 localdev 上运行的原因是我的 localdev 在 MacOS 上运行,而 Azure 中的管道在 Windows 上运行,就此而言,构建也将针对 net8.0 之上的

net8.0-windows10.0.19041.0
依次进行堵塞的 msbuild 导致上面提到的神秘错误。

希望这可以帮助某人避免因为问题而用头撞墙的两天。

© www.soinside.com 2019 - 2024. All rights reserved.