Skip to content

Commit bfad1f2

Browse files
Show a warning when the tools are used with a platform-specific app (#37868)
Fixes #32835 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
1 parent 365cbc3 commit bfad1f2

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/dotnet-ef/Properties/Resources.Designer.cs

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dotnet-ef/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@
330330
<data name="PrecompileQueriesWarning" xml:space="preserve">
331331
<value>Query precompilation is an experimental feature and should be used with caution.</value>
332332
</data>
333+
<data name="PlatformSpecificProject" xml:space="preserve">
334+
<value>Startup project '{startupProject}' targets a platform-specific framework: '{targetFrameworkValue}'. The Entity Framework Core .NET Command-line Tools might not function correctly. Implement IDesignTimeDbContextFactory&lt;&gt; to ensure design-time tools work correctly with this project. See https://aka.ms/efcore-docs-migrations-projects for more information.</value>
335+
</data>
333336
<data name="PrefixDescription" xml:space="preserve">
334337
<value>Prefix output with level.</value>
335338
</data>

src/dotnet-ef/RootCommand.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ protected override int Execute(string[] _)
106106
startupProject.AssemblyName + ".runtimeconfig.json");
107107
var projectAssetsFile = startupProject.ProjectAssetsFile;
108108

109+
if (!string.IsNullOrEmpty(startupProject.TargetPlatformIdentifier)
110+
|| HasPlatformInTargetFramework(startupProject.TargetFramework))
111+
{
112+
Reporter.WriteWarning(
113+
Resources.PlatformSpecificProject(startupProject.ProjectName, startupProject.TargetFramework));
114+
}
115+
109116
var targetFramework = new FrameworkName(startupProject.TargetFrameworkMoniker!);
110117
if (targetFramework.Identifier == ".NETFramework")
111118
{
@@ -309,6 +316,18 @@ private static string GetVersion()
309316
=> typeof(RootCommand).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!
310317
.InformationalVersion;
311318

319+
private static bool HasPlatformInTargetFramework(string? targetFramework)
320+
{
321+
if (string.IsNullOrEmpty(targetFramework))
322+
{
323+
return false;
324+
}
325+
326+
// Check for netX.Y-Z form (e.g. net8.0-windows10.0.19041.0)
327+
var dashIndex = targetFramework.IndexOf('-');
328+
return dashIndex > 0 && dashIndex < targetFramework.Length - 1;
329+
}
330+
312331
private static bool ShouldHelp(IReadOnlyList<string> commands, IList<string> args)
313332
=> args.Count == 0
314333
|| commands.Count == 0

0 commit comments

Comments
 (0)