Skip to content

Commit

Permalink
Tools: Warn/error when using new features on old runtimes
Browse files Browse the repository at this point in the history
Fixes #25153
  • Loading branch information
bricelam committed Sep 23, 2021
1 parent 5e382f1 commit e94739a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ef/Commands/DbContextOptimizeCommand.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Tools.Properties;

namespace Microsoft.EntityFrameworkCore.Tools.Commands
{
// ReSharper disable once ArrangeTypeModifiers
internal partial class DbContextOptimizeCommand
{
protected override int Execute(string[] args)
{
if (new SemanticVersionComparer().Compare(EFCoreVersion, "6.0.0") < 0)
{
throw new CommandException(Resources.VersionRequired("6.0.0"));
}

using var executor = CreateExecutor(args);
executor.OptimizeContext(
_outputDir!.Value(),
Expand Down
6 changes: 6 additions & 0 deletions src/ef/Commands/MigrationsListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,25 @@ private static void ReportJsonResults(IReadOnlyList<IDictionary> migrations)

private static void ReportResults(IEnumerable<IDictionary> migrations)
{
var anyUnknown = false;
var any = false;
foreach (var migration in migrations)
{
var id = migration["Id"] as string;
var applied = migration["Applied"] as bool?;
Reporter.WriteData($"{id}{(applied != false ? null : Resources.Pending)}");
anyUnknown |= !applied.HasValue;
any = true;
}

if (!any)
{
Reporter.WriteInformation(Resources.NoMigrations);
}
else if (anyUnknown)
{
Reporter.WriteWarning(Resources.PendingUnknown);
}
}
}
}
6 changes: 6 additions & 0 deletions src/ef/Properties/Resources.Designer.cs

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

3 changes: 3 additions & 0 deletions src/ef/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@
<data name="Pending" xml:space="preserve">
<value> (Pending)</value>
</data>
<data name="PendingUnknown" xml:space="preserve">
<value>Pending status not shown. Unable to determine which migrations have been applied. This can happen when your project uses a version of Entity Framework Core lower than 5.0.0 or when an error occurrs while accessing the database.</value>
</data>
<data name="PrefixDescription" xml:space="preserve">
<value>Prefix output with level.</value>
</data>
Expand Down

0 comments on commit e94739a

Please sign in to comment.