{"record":{"id":"dfb57adc1a2c8f94","repo":"dotnet/maui","slug":"error-building-dotnet-samples-with-nativeaot-is-o","errorCode":null,"errorMessage":"Error: Building dotnet-samples with NativeAOT is only supported in Release configuration","messagePattern":"Error: Building dotnet-samples with NativeAOT is only supported in Release configuration","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"eng/cake/dotnet.cake","lineNumber":184,"sourceCode":"\n        if (useNuget)\n        {\n            properties = new Dictionary<string, string>\n            {\n                [\"UseWorkload\"] = \"true\",\n                // [\"GenerateAppxPackageOnBuild\"] = \"true\",\n                [\"RestoreConfigFile\"] = tempDir.CombineWithFilePath(\"NuGet.config\").FullPath,\n            };\n        }\n\n        string projectsToBuild;\n        if (USE_NATIVE_AOT)\n        {\n            if (configuration.Equals(\"Debug\", StringComparison.OrdinalIgnoreCase))\n            {\n                var errMsg = $\"Error: Building dotnet-samples with NativeAOT is only supported in Release configuration\";\n                Error(errMsg);\n                throw new Exception(errMsg);\n            }\n            projectsToBuild = \"./src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj\";\n            properties[\"_UseNativeAot\"] = \"true\";\n            properties[\"RuntimeIdentifier\"] = \"iossimulator-x64\";\n            properties[\"BuildIpa\"] = \"true\";\n        }\n        else\n        {\n            projectsToBuild = \"./eng/Microsoft.Maui.Samples.slnf\";\n        }\n\n        RunMSBuildWithDotNet(projectsToBuild, properties, binlogPrefix: \"sample-\");\n    });\n\n// Builds the host app for the UI Tests\nTask(\"uitests-apphost\")\n    .IsDependentOn(\"dotnet-buildtasks\")\n    .Does(() =>","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/eng/cake/dotnet.cake#L166-L202","documentation":"Thrown by the 'dotnet-samples' Cake target when NativeAOT compilation is requested (USE_NATIVE_AOT=true) but the build configuration is Debug. NativeAOT ahead-of-time compilation for the iOS HostApp sample is only validated/supported in Release mode, so the script aborts before invoking MSBuild rather than producing a broken AOT binary.","triggerScenarios":"Invoking the samples build with both USE_NATIVE_AOT enabled and configuration set to \"Debug\" (case-insensitive). The check is configuration.Equals(\"Debug\", StringComparison.OrdinalIgnoreCase) inside the `if (USE_NATIVE_AOT)` block at dotnet.cake:184.","commonSituations":"Running the samples target locally with a default Debug configuration, or a CI job that sets USE_NATIVE_AOT=true without overriding configuration to Release. Also happens when a developer copies a NativeAOT job template but forgets the -configuration=Release argument.","solutions":["Pass --configuration=Release (or set the configuration argument/variable to Release) when running the dotnet-samples target with NativeAOT enabled.","If you did not intend NativeAOT, unset/disable USE_NATIVE_AOT so the standard Microsoft.Maui.Samples.slnf solution filter builds instead.","In CI, ensure the NativeAOT job matrix step sets configuration=Release explicitly before invoking cake."],"exampleFix":"// before\ncake --target=dotnet-samples --use_native_aot=true\n// after\ncake --target=dotnet-samples --use_native_aot=true --configuration=Release","handlingStrategy":"validation","validationCode":"// Validate before invoking the samples target\nif (USE_NATIVE_AOT && configuration.Equals(\"Debug\", StringComparison.OrdinalIgnoreCase)) {\n    Information(\"NativeAOT requires Release; forcing configuration=Release.\");\n    configuration = \"Release\";\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make the NativeAOT CI job explicitly set configuration=Release in the matrix.","Document that USE_NATIVE_AOT implies Release near the property assignments.","Consider auto-correcting Debug->Release with a warning instead of throwing for local runs."],"tags":["nativeaot","configuration","cake","build","maui-samples"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}