Title: Error NETSDK1005: Assets file doesn't have a target for 'net8.0-android' when building .NET Maui project with XUnit test in Azure DevOps pipelines
Question:
I'm encountering an error during the build process of my .NET Maui project in Azure DevOps pipelines. Here's the error message:
C:\hostedtoolcache\windows\dotnet\sdk\8.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: Assets file 'D:\a\1\s\SampleMauiApp.Test\obj\project.assets.json' doesn't have a target for 'net8.0-android'. Ensure that restore has run and that you have included 'net8.0-android' in the TargetFrameworks for your project.
Details:
- Project Configuration: The .NET Maui project (
SampleMauiApp.csproj) specifies the 'net8.0-android' target framework. Here's a snippet from the project file:
<TargetFramework>net8.0-android</TargetFramework>
Error Context: This error occurs during the build process in Azure DevOps pipelines, specifically while attempting to restore dependencies for the XUnit test project (
SampleMauiApp.Test). It seems related to the absence of the 'net8.0-android' target in theproject.assets.jsonfile.Pipeline Configuration: The Azure DevOps pipeline is configured to build the .NET Maui project and publish artifacts. Here's the pipeline configuration:
trigger:
- main
stages:
- stage: BuildAndroid
displayName: 'Build Android'
jobs:
- job: Build_MAUI_App
displayName: 'Build MAUI App Android'
pool:
vmImage: windows-latest
steps:
- task: JavaToolInstaller@0
inputs:
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
- task: UseDotNet@2
displayName: 'Use .NET Core SDK'
inputs:
packageType: 'sdk'
version: '8.0.x'
includePreviewVersions: true
- task: DotNetCoreCLI@2
displayName: 'Install MAUI Workloads'
inputs:
command: 'custom'
custom: 'workload'
arguments: 'install maui'
- task: DotNetCoreCLI@2
displayName: 'Restore NuGet Packages'
inputs:
command: 'restore'
projects: '**/*.sln'
feedsToUse: 'select'
- task: DotNetCoreCLI@2
displayName: 'Build Android Project'
inputs:
command: 'build'
projects: '**/*.sln'
arguments: '-f net8.0-android -c Release /p:AndroidSdkDirectory=$androidSdkPath'
- task: CopyFiles@2
displayName: 'Copy APK Files to Artifact Staging Directory'
inputs:
SourceFolder: '$(Agent.BuildDirectory)'
Contents: '**/*.apk'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Build Artifacts'
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)
ArtifactName: 'drop'
publishLocation: 'Container'
Full project code: https://github.com/Vinay206/SampleMauiApp
- Additional Context: The XUnit test project (
SampleMauiApp.Test) is referenced in the solution but not directly involved in the build process of the .NET Maui project. However, it seems to affect the dependency restoration process.
How can I resolve this error and successfully build my .NET 8.0 Maui project with XUnit test references in Azure DevOps pipelines? Any insights or suggestions would be greatly appreciated.
I attempted to build the solution using the Azure DevOps YAML provided above. How can I resolve this error?