C:\hostedtoolcache\windows\dotnet\sdk\9.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'D:\a\1\s\EFCore\obj\project.assets.json' doesn't have a target for 'net9.0-android'. Ensure that restore has run and that you have included 'net9.0-android' in the TargetFrameworks for your project. [D:\a\1\s\EFCore\EFCore.csproj]
Even I got the same When I tried your code, The error occurs because the EFCore project is built with the net9.0-android target, but that framework is not defined in the EFCore.csprojfile TargetFramework.
In your azure-pipeline.yml file contains below lines:
$csprojPath = Get-ChildItem -Path "$(Build.SourcesDirectory)" -Recurse -Filter *.csproj | Select-Object -First 1
$buildCommand = "dotnet build `"$($csprojPath.FullName)`" -c Release -f net9.0-android -v minimal -nologo -p:ApplicationVersion=$versionCode -p:ApplicationDisplayVersion=$appVersion -p:AndroidUseManagedDesignTimeResourceGenerator=false -p:AndroidEnableMultiDex=true -p:AndroidPackageFormat=apk"
This lines automatically finds the first .csproj file and build with the -f net9.0-android.
If your repository contains multiple projects, such as an EF Core library and a MAUI app, the build process might pick the first .csproj file it finds. If that file isn’t the MAUI app, it can cause build errors.
So, build the two projects separately, First build the EF core project then MAUI Android app.
task: PowerShell@2
displayName: 'Build EF Core library'
inputs:
targetType: 'inline'
script: |
Write-Host "Building EF Core project..."
dotnet build "$(Build.SourcesDirectory)/EFCore/EFCore.csproj" -c Release
- task: PowerShell@2
displayName: 'Build MAUI Android App'
inputs:
targetType: 'inline'
script: |
$appVersion = $env:AppVersion
$versionCode = $env:BUILD_BUILDID
if (-not $appVersion) {
Write-Host "❌ Error: AppVersion is not set." -ForegroundColor Red
exit 1
}
if (-not $versionCode -or $versionCode -notmatch '^\d+$') {
Write-Host "❌ Error: VersionCode is invalid or not set." -ForegroundColor Red
exit 1
}
Write-Host "Building MAUI Android project..."
dotnet build "$(Build.SourcesDirectory)/maui-efcore-pipeline-build/maui-efcore-pipeline-build.csproj" `
-c Release `
-f net9.0-android `
-p:ApplicationVersion=$versionCode `
-p:ApplicationDisplayVersion=$appVersion `
-p:AndroidUseManagedDesignTimeResourceGenerator=false `
-p:AndroidEnableMultiDex=true `
-p:AndroidPackageFormat=apk
Output:
