Search code examples
c#.netmsbuildazure-pipelinesnuget

Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: Assets file 'obj\project.assets.json' doesn't have a target for 'net8.0'


I have a simple C# project with the following .csproj file:

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

When I try to build it on localdev using 'dotnet build Foo.csproj' then everything works without issues. But when I use the same command on Azure I get the following cryptic error:

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'

Solution

  • (and to answer my own question ...) The error was that I was using:

    <TargetFramework>net8.0</TargetFramework>
    

    While I should have been using:

    <TargetFrameworks>net8.0</TargetFrameworks>
    

    The reason for which the build was working on localdev is that my localdev is running on MacOS while the pipeline in Azure is running on Windows and for that matter the build would also target net8.0-windows10.0.19041.0 on top of net8.0 and this in turn clogged msbuild causing the cryptic error mentioned above.

    Hope this helps someone save 2 days of banging his own head against the wall over what's wrong.