Skip to content

Commit

Permalink
Implement remaining Migrations Bundles features
Browse files Browse the repository at this point in the history
Changes:
- Use TargetFramework from startup project
- Add --output and --force
- Fix --runtime and --self-contained
- Output bundle path
- Move the MigrationsBundle class under the Migrations namespace

Fixes dotnet#19693, part of dotnet#24743
  • Loading branch information
bricelam committed Aug 16, 2021
1 parent cc1d81a commit 65fd0cb
Show file tree
Hide file tree
Showing 22 changed files with 430 additions and 147 deletions.
20 changes: 10 additions & 10 deletions All.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28418.106
# Visual Studio Version 17
VisualStudioVersion = 17.0.31521.260
MinimumVisualStudioVersion = 16.0.28418.106
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B9E4CC99-199C-4E3B-9EC5-D1FDFCD6C27B}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -102,23 +102,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.Benchmarks
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Sqlite.Benchmarks", "benchmark\EFCore.Sqlite.Benchmarks\EFCore.Sqlite.Benchmarks.csproj", "{5A44F67E-517F-458D-B9C7-12A4DBBAD64A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.Benchmarks", "benchmark\EFCore.Benchmarks\EFCore.Benchmarks.csproj", "{2642F4F0-69BE-4C43-94B7-B298FEC87D89}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Benchmarks", "benchmark\EFCore.Benchmarks\EFCore.Benchmarks.csproj", "{2642F4F0-69BE-4C43-94B7-B298FEC87D89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.e_sqlcipher.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj", "{7B598E0C-B8E2-4F1F-B53C-ED84178E65BE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Sqlite.e_sqlcipher.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj", "{7B598E0C-B8E2-4F1F-B53C-ED84178E65BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.winsqlite3.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.winsqlite3.Tests.csproj", "{B163761D-FB4A-4C80-BAB9-01905E1351EF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Sqlite.winsqlite3.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.winsqlite3.Tests.csproj", "{B163761D-FB4A-4C80-BAB9-01905E1351EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.sqlite3.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.sqlite3.Tests.csproj", "{E0FF35C8-8038-4394-9C2A-AF34BE3CC61F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Sqlite.sqlite3.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.sqlite3.Tests.csproj", "{E0FF35C8-8038-4394-9C2A-AF34BE3CC61F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.OData.FunctionalTests", "test\EFCore.OData.FunctionalTests\EFCore.OData.FunctionalTests.csproj", "{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.Specification.Tests", "test\EFCore.AspNet.Specification.Tests\EFCore.AspNet.Specification.Tests.csproj", "{80A812BF-8AB7-4197-AC1C-712BA5E818FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.Specification.Tests", "test\EFCore.AspNet.Specification.Tests\EFCore.AspNet.Specification.Tests.csproj", "{80A812BF-8AB7-4197-AC1C-712BA5E818FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.SqlServer.FunctionalTests", "test\EFCore.AspNet.SqlServer.FunctionalTests\EFCore.AspNet.SqlServer.FunctionalTests.csproj", "{F956A344-5C8D-4015-A3BF-7A8304C58BE4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.SqlServer.FunctionalTests", "test\EFCore.AspNet.SqlServer.FunctionalTests\EFCore.AspNet.SqlServer.FunctionalTests.csproj", "{F956A344-5C8D-4015-A3BF-7A8304C58BE4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.Sqlite.FunctionalTests", "test\EFCore.AspNet.Sqlite.FunctionalTests\EFCore.AspNet.Sqlite.FunctionalTests.csproj", "{CC93C465-F5AC-4CB9-A064-3675955962F4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.Sqlite.FunctionalTests", "test\EFCore.AspNet.Sqlite.FunctionalTests\EFCore.AspNet.Sqlite.FunctionalTests.csproj", "{CC93C465-F5AC-4CB9-A064-3675955962F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.InMemory.FunctionalTests", "test\EFCore.AspNet.InMemory.FunctionalTests\EFCore.AspNet.InMemory.FunctionalTests.csproj", "{F1B2E5A0-8C74-414A-B262-353FEE325E9F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.InMemory.FunctionalTests", "test\EFCore.AspNet.InMemory.FunctionalTests\EFCore.AspNet.InMemory.FunctionalTests.csproj", "{F1B2E5A0-8C74-414A-B262-353FEE325E9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Reflection;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Tools;

namespace Microsoft.EntityFrameworkCore.Design
namespace Microsoft.EntityFrameworkCore.Migrations.Design
{
/// <summary>
/// Defines the entry point for Migations bundles.
/// Defines the entry point for Migrations bundles.
/// </summary>
public static class MigrationsBundle
{
private static string? _context;
private static Assembly? _assembly;
private static Assembly? _startupAssembly;
private static CommandArgument? _migration;
private static CommandOption? _connection;

/// <summary>
/// The entry point for Migrations bundles.
/// </summary>
/// <param name="context"> The DbContext to use. </param>
/// <param name="assembly"> The Migrations assembly. </param>
/// <param name="startupAssembly"> The startup assembly. </param>
/// <param name="args"> The command-line arguemnts. </param>
/// <returns> Zero if the command succeedes; otherwise, one. </returns>
/// <param name="args"> The command-line arguments. </param>
/// <returns> Zero if the command succeeds; otherwise, one. </returns>
public static int Execute(string? context, Assembly assembly, Assembly startupAssembly, string[] args)
{
_context = context;
_assembly = assembly;
_startupAssembly = startupAssembly;

var app = new CommandLineApplication
{
Name = "bundle",
FullName = DesignStrings.BundleFullName,
HandleResponseFiles = true
};

var migration = app.Argument("<MIGRATION>", DesignStrings.MigrationDescription);
var connection = app.Option("--connection <CONNECTION>", DesignStrings.ConnectionDescription);

app.VersionOption("--version", ProductInfo.GetVersion);
app.HelpOption("-h|--help");
var verbose = app.Option("-v|--verbose", DesignStrings.VerboseDescription);
var noColor = app.Option("--no-color", DesignStrings.NoColorDescription);
var prefixOutput = app.Option("--prefix-output", DesignStrings.PrefixDescription);

app.OnExecute(
args =>
{
Reporter.IsVerbose = verbose.HasValue();
Reporter.NoColor = noColor.HasValue();
Reporter.PrefixOutput = prefixOutput.HasValue();

ExecuteInternal(context, assembly, startupAssembly, args, migration.Value, connection.Value());

return 0;
});
Configure(app);

try
{
Expand All @@ -76,13 +65,34 @@ public static int Execute(string? context, Assembly assembly, Assembly startupAs
}
}

private static void ExecuteInternal(
string? context,
Assembly assembly,
Assembly startupAssembly,
string[] args,
string? migration,
string? connection)
// Internal for testing
internal static void Configure(CommandLineApplication app)
{
app.FullName = DesignStrings.BundleFullName;

_migration = app.Argument("<MIGRATION>", DesignStrings.MigrationDescription);
_connection = app.Option("--connection <CONNECTION>", DesignStrings.ConnectionDescription);

app.VersionOption("--version", ProductInfo.GetVersion);
app.HelpOption("-h|--help");
var verbose = app.Option("-v|--verbose", DesignStrings.VerboseDescription);
var noColor = app.Option("--no-color", DesignStrings.NoColorDescription);
var prefixOutput = app.Option("--prefix-output", DesignStrings.PrefixDescription);

app.OnExecute(
args =>
{
Reporter.IsVerbose = verbose.HasValue();
Reporter.NoColor = noColor.HasValue();
Reporter.PrefixOutput = prefixOutput.HasValue();

ExecuteInternal(args);

return 0;
});
}

private static void ExecuteInternal(string[] args)
{
new MigrationsOperations(
new OperationReporter(
Expand All @@ -91,14 +101,14 @@ private static void ExecuteInternal(
Reporter.WriteWarning,
Reporter.WriteInformation,
Reporter.WriteVerbose)),
assembly,
startupAssembly,
_assembly!,
_startupAssembly!,
projectDir: string.Empty,
rootNamespace: null,
language: null,
nullable: false,
args)
.UpdateDatabase(migration, connection, context);
.UpdateDatabase(_migration!.Value, _connection!.Value(), _context);
}
}
}
7 changes: 7 additions & 0 deletions src/EFCore.Design/Properties/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo(
"Microsoft.EntityFrameworkCore.Design.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
18 changes: 13 additions & 5 deletions src/EFCore.Tools/tools/EntityFrameworkCore.PS2.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,23 @@ function Add-Migration(
.DESCRIPTION
Creates an executable to update the database.
.PARAMETER Output
The path of executable file to create.
.PARAMETER Force
Overwrite existing files.
.PARAMETER SelfContained
Also bundle the .NET runtime so it doesn't need to be installed on the machine.
.PARAMETER Runtime
The target runtime to bundle for.
.PARAMETER Configuration
The configuration to use.
The configuration to use for the bundle.
.PARAMETER Framework
The target framework. Defaults to the first one in the project.
.PARAMETER Context
The DbContext to use.
Expand All @@ -74,9 +83,6 @@ function Add-Migration(
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
.PARAMETER Namespace
The namespace to use. Matches the directory by default.
.PARAMETER Args
Arguments passed to the application.
Expand All @@ -86,13 +92,15 @@ function Add-Migration(
about_EntityFrameworkCore
#>
function Bundle-Migration(
$Output,
[switch] $Force,
[switch] $SelfContained,
$Runtime,
$Configuration,
$Framework,
$Context,
$Project,
$StartupProject,
$Namespace,
$Args)
{
throw $UpdatePowerShell
Expand Down
40 changes: 31 additions & 9 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,23 @@ Register-TabExpansion Bundle-Migration @{
.DESCRIPTION
Creates an executable to update the database.
.PARAMETER Output
The path of executable file to create.
.PARAMETER Force
Overwrite existing files.
.PARAMETER SelfContained
Also bundle the .NET runtime so it doesn't need to be installed on the machine.
.PARAMETER Runtime
The target runtime to bundle for.
.PARAMETER Configuration
The configuration to use.
The configuration to use for the bundle.
.PARAMETER Framework
The target framework. Defaults to the first one in the project.
.PARAMETER Context
The DbContext to use.
Expand All @@ -128,9 +137,6 @@ Register-TabExpansion Bundle-Migration @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
.PARAMETER Namespace
The namespace to use. Matches the directory by default.
.PARAMETER Args
Arguments passed to the application.
Expand All @@ -143,20 +149,36 @@ function Bundle-Migration
{
[CmdletBinding(PositionalBinding = $false)]
param(
[string] $Output,
[switch] $Force,
[switch] $SelfContained,
[string] $Runtime,
[string] $Configuration,
[string] $OutputDir,
[string] $Framework,
[string] $Context,
[string] $Project,
[string] $StartupProject,
[string] $Namespace,
[string] $Args)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject

$params = 'migrations', 'bundle'
if (!$Framework)
{
$Framework = GetProperty $startupProject.Properties 'FriendlyTargetFramework'
}

$params = 'migrations', 'bundle', '--framework', $Framework

if ($Output)
{
$params += '--output', $Output
}

if ($Force)
{
$params += '--force'
}

if ($SelfContained)
{
Expand All @@ -165,12 +187,12 @@ function Bundle-Migration

if ($Runtime)
{
$params += '--runtime', $Runtime
$params += '--bundle-runtime', $Runtime
}

if ($Configuration)
{
$params += '--configuration', $Configuration
$params += '--bundle-configuration', $Configuration
}

$params += GetParams $Context
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 @@ -40,6 +40,7 @@ public Project(string file, string? framework, string? configuration, string? ru
public string? TargetFileName { get; set; }
public string? TargetFrameworkMoniker { get; set; }
public string? Nullable { get; set; }
public string? TargetFramework { get; set; }

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

Expand Down
20 changes: 18 additions & 2 deletions src/dotnet-ef/Properties/Resources.Designer.cs

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

Loading

0 comments on commit 65fd0cb

Please sign in to comment.