Skip to content

Commit cf0e0e6

Browse files
CopilotAndriySvyryd
andcommitted
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
1 parent bfad1f2 commit cf0e0e6

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

src/EFCore.Tools/tools/EntityFrameworkCore.psm1

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,21 +1284,25 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip
12841284
$frameworkName = New-Object 'System.Runtime.Versioning.FrameworkName' $targetFrameworkMoniker
12851285
$targetFramework = $frameworkName.Identifier
12861286

1287+
$targetPlatformIdentifier = $null
1288+
$targetFrameworkValue = $null
1289+
if (IsCpsProject $startupProject)
1290+
{
1291+
$targetPlatformIdentifier = GetCpsProperty $startupProject 'TargetPlatformIdentifier'
1292+
$targetFrameworkValue = GetCpsProperty $startupProject 'TargetFramework'
1293+
}
1294+
if ($targetPlatformIdentifier -or (HasPlatformInTargetFramework $targetFrameworkValue))
1295+
{
1296+
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."
1297+
}
1298+
12871299
if ($targetFramework -in '.NETFramework')
12881300
{
12891301
throw "Startup project '$($startupProject.ProjectName)' targets framework '.NETFramework'. The Entity Framework Core Package " +
12901302
'Manager Console Tools don''t support .NET Framework projects. Consider updating the project to target .NET.'
12911303
}
12921304
elseif ($targetFramework -eq '.NETCoreApp')
12931305
{
1294-
$targetPlatformIdentifier = GetCpsProperty $startupProject 'TargetPlatformIdentifier'
1295-
if ($targetPlatformIdentifier -and $targetPlatformIdentifier -ne 'Windows')
1296-
{
1297-
throw "Startup project '$($startupProject.ProjectName)' targets platform '$targetPlatformIdentifier'. The Entity Framework " +
1298-
'Core Package Manager Console Tools don''t support this platform. See https://aka.ms/efcore-docs-pmc-tfms for more ' +
1299-
'information.'
1300-
}
1301-
13021306
$exePath = (Get-Command 'dotnet').Path
13031307

13041308
$startupTargetName = GetProperty $startupProject.Properties 'AssemblyName'
@@ -1502,6 +1506,18 @@ function IsCpsProject($project)
15021506
return $isCapabilityMatch.Invoke($null, ($hierarchy, 'CPS'))
15031507
}
15041508

1509+
function HasPlatformInTargetFramework($targetFramework)
1510+
{
1511+
if (-not $targetFramework)
1512+
{
1513+
return $false
1514+
}
1515+
1516+
# Check for netX.Y-Z form (e.g. net8.0-windows10.0.19041.0)
1517+
$dashIndex = $targetFramework.IndexOf('-')
1518+
return $dashIndex -gt 0 -and $dashIndex -lt ($targetFramework.Length - 1)
1519+
}
1520+
15051521
function IsWeb($project)
15061522
{
15071523
$types = GetProjectTypes $project

0 commit comments

Comments
 (0)