Skip to content

Commit

Permalink
Tools: Check for unsupported OS-specific TFMs
Browse files Browse the repository at this point in the history
Fixes #25938
  • Loading branch information
bricelam committed Sep 20, 2021
1 parent ccde2d5 commit f05ea6e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,14 @@ 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'
Expand Down Expand Up @@ -1279,8 +1287,8 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip
}
else
{
throw "Startup project '$($startupProject.ProjectName)' targets framework '$targetFramework'. " +
'The Entity Framework Core Package Manager Console Tools don''t support this framework.'
throw "Startup project '$($startupProject.ProjectName)' targets framework '$targetFramework'. The Entity Framework Core Package " +
'Manager Console Tools don''t support this framework. See https://aka.ms/efcore-docs-pmc-tfms for more information.'
}

$projectDir = GetProperty $project.Properties 'FullPath'
Expand Down
4 changes: 3 additions & 1 deletion src/dotnet-ef/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public Project(string file, string? framework, string? configuration, string? ru
public string? TargetFrameworkMoniker { get; set; }
public string? Nullable { get; set; }
public string? TargetFramework { get; set; }
public string? TargetPlatformIdentifier { get; set; }

public static Project FromFile(
string file,
Expand Down Expand Up @@ -137,7 +138,8 @@ public static Project FromFile(
TargetFileName = metadata["TargetFileName"],
TargetFrameworkMoniker = metadata["TargetFrameworkMoniker"],
Nullable = metadata["Nullable"],
TargetFramework = metadata["TargetFramework"]
TargetFramework = metadata["TargetFramework"],
TargetPlatformIdentifier = metadata["TargetPlatformIdentifier"]
};
}

Expand Down
10 changes: 9 additions & 1 deletion src/dotnet-ef/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/dotnet-ef/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@
<value>The tables to generate entity types for.</value>
</data>
<data name="UnsupportedFramework" xml:space="preserve">
<value>Startup project '{startupProject}' targets framework '{targetFramework}'. The Entity Framework Core .NET Command-line Tools don't support this framework.</value>
<value>Startup project '{startupProject}' targets framework '{targetFramework}'. The Entity Framework Core .NET Command-line Tools don't support this framework. See https://aka.ms/efcore-docs-cli-tfms for more information.</value>
</data>
<data name="UnsupportedPlatform" xml:space="preserve">
<value>Startup project '{startupProject}' targets platform '{targetPlatform}'. The Entity Framework Core .NET Command-line Tools don't support this platform. See https://aka.ms/efcore-docs-cli-tfms for more information.</value>
</data>
<data name="UseDatabaseNamesDescription" xml:space="preserve">
<value>Use table and column names directly from the database.</value>
Expand Down
3 changes: 2 additions & 1 deletion src/dotnet-ef/Resources/EntityFrameworkCore.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetEFProjectMetadata" Condition="">
<Target Name="GetEFProjectMetadata">
<MSBuild Condition=" '$(TargetFramework)' == '' "
Projects="$(MSBuildProjectFile)"
Targets="GetEFProjectMetadata"
Expand All @@ -19,6 +19,7 @@
<EFProjectMetadata Include="TargetFrameworkMoniker: $(TargetFrameworkMoniker)" />
<EFProjectMetadata Include="Nullable: $(Nullable)" />
<EFProjectMetadata Include="TargetFramework: $(TargetFramework)" />
<EFProjectMetadata Include="TargetPlatformIdentifier: $(TargetPlatformIdentifier)" />
</ItemGroup>
<WriteLinesToFile Condition=" '$(TargetFramework)' != '' "
File="$(EFProjectMetadataFile)"
Expand Down
7 changes: 7 additions & 0 deletions src/dotnet-ef/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ protected override int Execute(string[] _)
Resources.NETCoreApp1StartupProject(startupProject.ProjectName, targetFramework.Version));
}

var targetPlatformIdentifier = startupProject.TargetPlatformIdentifier!;
if (targetPlatformIdentifier.Length != 0
&& !string.Equals(targetPlatformIdentifier, "Windows", StringComparison.OrdinalIgnoreCase))
{
throw new CommandException(Resources.UnsupportedPlatform(startupProject.ProjectName, targetPlatformIdentifier));
}

executable = "dotnet";
args.Add("exec");
args.Add("--depsfile");
Expand Down

0 comments on commit f05ea6e

Please sign in to comment.