From cf0e0e6db4d1d57bbcb94747f23d806afbe540ba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 18:57:03 +0000 Subject: [PATCH 1/3] Show a warning when the PMC tools are used with a platform-specific app Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/20243169-49f2-4777-a5a3-2f3d1b2b00ef --- .../tools/EntityFrameworkCore.psm1 | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 index bd3dfc51311..4fc0d0c278b 100644 --- a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 +++ b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 @@ -1284,6 +1284,18 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip $frameworkName = New-Object 'System.Runtime.Versioning.FrameworkName' $targetFrameworkMoniker $targetFramework = $frameworkName.Identifier + $targetPlatformIdentifier = $null + $targetFrameworkValue = $null + if (IsCpsProject $startupProject) + { + $targetPlatformIdentifier = GetCpsProperty $startupProject 'TargetPlatformIdentifier' + $targetFrameworkValue = GetCpsProperty $startupProject 'TargetFramework' + } + if ($targetPlatformIdentifier -or (HasPlatformInTargetFramework $targetFrameworkValue)) + { + Write-Warning "Startup project '$($startupProject.ProjectName)' targets a platform-specific framework: '$targetFrameworkValue'. The Entity Framework Core Package Manager Console Tools might not function correctly. Implement IDesignTimeDbContextFactory<> to ensure design-time tools work correctly with this project. See https://aka.ms/efcore-docs-migrations-projects for more information." + } + if ($targetFramework -in '.NETFramework') { throw "Startup project '$($startupProject.ProjectName)' targets framework '.NETFramework'. The Entity Framework Core Package " + @@ -1291,14 +1303,6 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip } elseif ($targetFramework -eq '.NETCoreApp') { - $targetPlatformIdentifier = GetCpsProperty $startupProject 'TargetPlatformIdentifier' - if ($targetPlatformIdentifier -and $targetPlatformIdentifier -ne 'Windows') - { - throw "Startup project '$($startupProject.ProjectName)' targets platform '$targetPlatformIdentifier'. The Entity Framework " + - 'Core Package Manager Console Tools don''t support this platform. See https://aka.ms/efcore-docs-pmc-tfms for more ' + - 'information.' - } - $exePath = (Get-Command 'dotnet').Path $startupTargetName = GetProperty $startupProject.Properties 'AssemblyName' @@ -1502,6 +1506,18 @@ function IsCpsProject($project) return $isCapabilityMatch.Invoke($null, ($hierarchy, 'CPS')) } +function HasPlatformInTargetFramework($targetFramework) +{ + if (-not $targetFramework) + { + return $false + } + + # Check for netX.Y-Z form (e.g. net8.0-windows10.0.19041.0) + $dashIndex = $targetFramework.IndexOf('-') + return $dashIndex -gt 0 -and $dashIndex -lt ($targetFramework.Length - 1) +} + function IsWeb($project) { $types = GetProjectTypes $project From f2ccf9ea1c648b7d0cda772dd3bf6f34e8e3e5d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 20:17:58 +0000 Subject: [PATCH 2/3] Address review: move warning inside .NETCoreApp block, preserve error, inline helper Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/55267e08-667f-4ff4-8181-dd67b66dae0a --- .../tools/EntityFrameworkCore.psm1 | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 index 4fc0d0c278b..5d8f9206bb1 100644 --- a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 +++ b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 @@ -1284,18 +1284,6 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip $frameworkName = New-Object 'System.Runtime.Versioning.FrameworkName' $targetFrameworkMoniker $targetFramework = $frameworkName.Identifier - $targetPlatformIdentifier = $null - $targetFrameworkValue = $null - if (IsCpsProject $startupProject) - { - $targetPlatformIdentifier = GetCpsProperty $startupProject 'TargetPlatformIdentifier' - $targetFrameworkValue = GetCpsProperty $startupProject 'TargetFramework' - } - if ($targetPlatformIdentifier -or (HasPlatformInTargetFramework $targetFrameworkValue)) - { - Write-Warning "Startup project '$($startupProject.ProjectName)' targets a platform-specific framework: '$targetFrameworkValue'. The Entity Framework Core Package Manager Console Tools might not function correctly. Implement IDesignTimeDbContextFactory<> to ensure design-time tools work correctly with this project. See https://aka.ms/efcore-docs-migrations-projects for more information." - } - if ($targetFramework -in '.NETFramework') { throw "Startup project '$($startupProject.ProjectName)' targets framework '.NETFramework'. The Entity Framework Core Package " + @@ -1303,6 +1291,20 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip } elseif ($targetFramework -eq '.NETCoreApp') { + $targetPlatformIdentifier = GetCpsProperty $startupProject 'TargetPlatformIdentifier' + $targetFrameworkValue = GetCpsProperty $startupProject 'TargetFramework' + if ($targetPlatformIdentifier -or ($targetFrameworkValue -and $targetFrameworkValue.IndexOf('-') -gt 0 -and $targetFrameworkValue.IndexOf('-') -lt ($targetFrameworkValue.Length - 1))) + { + Write-Warning "Startup project '$($startupProject.ProjectName)' targets a platform-specific framework: '$targetFrameworkValue'. The Entity Framework Core Package Manager Console Tools might not function correctly. Implement IDesignTimeDbContextFactory<> to ensure design-time tools work correctly with this project. See https://aka.ms/efcore-docs-migrations-projects for more information." + } + + if ($targetPlatformIdentifier -and $targetPlatformIdentifier -ne 'Windows') + { + throw "Startup project '$($startupProject.ProjectName)' targets platform '$targetPlatformIdentifier'. The Entity Framework " + + 'Core Package Manager Console Tools don''t support this platform. See https://aka.ms/efcore-docs-pmc-tfms for more ' + + 'information.' + } + $exePath = (Get-Command 'dotnet').Path $startupTargetName = GetProperty $startupProject.Properties 'AssemblyName' @@ -1506,18 +1508,6 @@ function IsCpsProject($project) return $isCapabilityMatch.Invoke($null, ($hierarchy, 'CPS')) } -function HasPlatformInTargetFramework($targetFramework) -{ - if (-not $targetFramework) - { - return $false - } - - # Check for netX.Y-Z form (e.g. net8.0-windows10.0.19041.0) - $dashIndex = $targetFramework.IndexOf('-') - return $dashIndex -gt 0 -and $dashIndex -lt ($targetFramework.Length - 1) -} - function IsWeb($project) { $types = GetProjectTypes $project From 5058f76b2682c2ec01fdfe2494d5f14a964b48a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 20:29:19 +0000 Subject: [PATCH 3/3] Optimize dash index check and wrap long lines under 140 chars Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/d37e057a-ba63-4672-a8ec-808574c75bc9 --- src/EFCore.Tools/tools/EntityFrameworkCore.psm1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 index 5d8f9206bb1..4fc7e77cb86 100644 --- a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 +++ b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 @@ -1293,9 +1293,14 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip { $targetPlatformIdentifier = GetCpsProperty $startupProject 'TargetPlatformIdentifier' $targetFrameworkValue = GetCpsProperty $startupProject 'TargetFramework' - if ($targetPlatformIdentifier -or ($targetFrameworkValue -and $targetFrameworkValue.IndexOf('-') -gt 0 -and $targetFrameworkValue.IndexOf('-') -lt ($targetFrameworkValue.Length - 1))) + $dashIndex = if ($targetFrameworkValue) { $targetFrameworkValue.IndexOf('-') } else { -1 } + if ($targetPlatformIdentifier -or $dashIndex -gt 0) { - Write-Warning "Startup project '$($startupProject.ProjectName)' targets a platform-specific framework: '$targetFrameworkValue'. The Entity Framework Core Package Manager Console Tools might not function correctly. Implement IDesignTimeDbContextFactory<> to ensure design-time tools work correctly with this project. See https://aka.ms/efcore-docs-migrations-projects for more information." + Write-Warning ("Startup project '$($startupProject.ProjectName)' targets a platform-specific" + + " framework: '$targetFrameworkValue'. The Entity Framework Core Package Manager Console" + + ' Tools might not function correctly. Implement IDesignTimeDbContextFactory<> to ensure' + + ' design-time tools work correctly with this project.' + + ' See https://aka.ms/efcore-docs-migrations-projects for more information.') } if ($targetPlatformIdentifier -and $targetPlatformIdentifier -ne 'Windows')