0

I am unable to build my MAUI project that uses Entity Framework Core with migrations in Azure; I am able to build it locally.

I get this error when building in Azure:

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]

The project structure is the main project that contains all MAUI related items, then, another project for EF Core, this contains the DbContext, factory (for migrations) and entities.

I've created a sample project that also includes a YAML file: https://github.com/d-harding/maui-efcore-pipeline-build/

Thanks for any help.

1
  • Try modifying your YAML file to build the two projects separately, one after the other. Commented Jun 9 at 11:40

1 Answer 1

1

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:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Building EF then MAUI worked for my sample project, took more work within the solution for my other project and I am not sure why. EFCore needed both <GenerateAssemblyInfo>false</GenerateAssemblyInfo>, <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.