diff --git a/src/EFCore.Design/Design/DbContextActivator.cs b/src/EFCore.Design/Design/DbContextActivator.cs
index e41a7f54439..9eb25ec0395 100644
--- a/src/EFCore.Design/Design/DbContextActivator.cs
+++ b/src/EFCore.Design/Design/DbContextActivator.cs
@@ -22,11 +22,13 @@ public static class DbContextActivator
/// The type to instantiate.
/// The application's startup assembly.
/// The design-time report handler.
+ /// Arguments passed to the application.
/// The newly created object.
public static DbContext CreateInstance(
[NotNull] Type contextType,
[CanBeNull] Assembly startupAssembly = null,
- [CanBeNull] IOperationReportHandler reportHandler = null)
+ [CanBeNull] IOperationReportHandler reportHandler = null,
+ [CanBeNull] string[] arguments = null)
{
Check.NotNull(contextType, nameof(contextType));
@@ -34,7 +36,7 @@ public static DbContext CreateInstance(
new OperationReporter(reportHandler),
contextType.Assembly,
startupAssembly ?? contextType.Assembly,
- args: Array.Empty()) // TODO: Issue #8332
+ args: arguments ?? Array.Empty())
.CreateContext(contextType.FullName);
}
}
diff --git a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs
index 77033f82a00..93f5e91884c 100644
--- a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs
+++ b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs
@@ -25,6 +25,7 @@ public class DatabaseOperations
private readonly string _rootNamespace;
private readonly string _language;
private readonly DesignTimeServicesBuilder _servicesBuilder;
+ private readonly string[] _args;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -51,8 +52,9 @@ public DatabaseOperations(
_projectDir = projectDir;
_rootNamespace = rootNamespace;
_language = language;
+ _args = args;
- _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args);
+ _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, _args);
}
///
diff --git a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs
index 24364a798ff..929af196986 100644
--- a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs
+++ b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs
@@ -32,6 +32,7 @@ public class MigrationsOperations
private readonly string _language;
private readonly DesignTimeServicesBuilder _servicesBuilder;
private readonly DbContextOperations _contextOperations;
+ private readonly string[] _args;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -60,13 +61,14 @@ public MigrationsOperations(
_projectDir = projectDir;
_rootNamespace = rootNamespace;
_language = language;
+ _args = args;
_contextOperations = new DbContextOperations(
reporter,
assembly,
startupAssembly,
- args);
+ _args);
- _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args);
+ _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, _args);
}
///
diff --git a/src/EFCore.Design/Design/OperationExecutor.cs b/src/EFCore.Design/Design/OperationExecutor.cs
index 755223fda9f..2227eb31fca 100644
--- a/src/EFCore.Design/Design/OperationExecutor.cs
+++ b/src/EFCore.Design/Design/OperationExecutor.cs
@@ -47,6 +47,8 @@ public class OperationExecutor : MarshalByRefObject
/// startupTargetName--The assembly name of the startup project.
/// projectDir--The target project's root directory.
/// rootNamespace--The target project's root namespace.
+ /// language--The programming language to be used to generate classes.
+ /// remainingArguments--Extra arguments passed into the operation.
///
/// The .
/// The executor arguments.
@@ -61,9 +63,7 @@ public OperationExecutor([NotNull] IOperationReportHandler reportHandler, [NotNu
_projectDir = (string)args["projectDir"];
_rootNamespace = (string)args["rootNamespace"];
_language = (string)args["language"];
-
- // TODO: Flow in from tools (issue #8332)
- _designArgs = Array.Empty();
+ _designArgs = (string[])args["remainingArguments"];
var toolsVersion = (string)args["toolsVersion"];
var runtimeVersion = ProductInfo.GetVersion();
diff --git a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1
index fd44f78e08d..8805473b27d 100644
--- a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1
+++ b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1
@@ -36,6 +36,9 @@ Register-TabExpansion Add-Migration @{
.PARAMETER Namespace
Specify to override the namespace for the migration.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
Remove-Migration
Update-Database
@@ -51,7 +54,9 @@ function Add-Migration
[string] $Context,
[string] $Project,
[string] $StartupProject,
- [string] $Namespace)
+ [string] $Namespace,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
WarnIfEF6 'Add-Migration'
@@ -71,6 +76,7 @@ function Add-Migration
}
$params += GetParams $Context
+ $params += $RemainingArguments
# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
@@ -111,6 +117,9 @@ Register-TabExpansion Drop-Database @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
Update-Database
about_EntityFrameworkCore
@@ -118,7 +127,12 @@ Register-TabExpansion Drop-Database @{
function Drop-Database
{
[CmdletBinding(PositionalBinding = $false, SupportsShouldProcess = $true, ConfirmImpact = 'High')]
- param([string] $Context, [string] $Project, [string] $StartupProject)
+ param(
+ [string] $Context,
+ [string] $Project,
+ [string] $StartupProject,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
@@ -129,6 +143,7 @@ function Drop-Database
{
$params = 'database', 'drop', '--force'
$params += GetParams $Context
+ $params += $RemainingArguments
EF $dteProject $dteStartupProject $params -skipBuild
}
@@ -170,13 +185,21 @@ Register-TabExpansion Get-DbContext @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
about_EntityFrameworkCore
#>
function Get-DbContext
{
[CmdletBinding(PositionalBinding = $false)]
- param([string] $Context, [string] $Project, [string] $StartupProject)
+ param(
+ [string] $Context,
+ [string] $Project,
+ [string] $StartupProject,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
@@ -185,6 +208,7 @@ function Get-DbContext
{
$params = 'dbcontext', 'info', '--json'
$params += GetParams $Context
+ $params += $RemainingArguments
# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
return (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
}
@@ -225,6 +249,9 @@ Register-TabExpansion Remove-Migration @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
Add-Migration
about_EntityFrameworkCore
@@ -232,7 +259,13 @@ Register-TabExpansion Remove-Migration @{
function Remove-Migration
{
[CmdletBinding(PositionalBinding = $false)]
- param([switch] $Force, [string] $Context, [string] $Project, [string] $StartupProject)
+ param(
+ [switch] $Force,
+ [string] $Context,
+ [string] $Project,
+ [string] $StartupProject,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
@@ -245,6 +278,7 @@ function Remove-Migration
}
$params += GetParams $Context
+ $params += $RemainingArguments
# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
@@ -320,6 +354,9 @@ Register-TabExpansion Scaffold-DbContext @{
.PARAMETER ContextNamespace
Specify to override the namespace for the DbContext class.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
about_EntityFrameworkCore
#>
@@ -342,7 +379,9 @@ function Scaffold-DbContext
[string] $Project,
[string] $StartupProject,
[string] $Namespace,
- [string] $ContextNamespace)
+ [string] $ContextNamespace,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
@@ -392,6 +431,8 @@ function Scaffold-DbContext
$params += '--force'
}
+ $params += $RemainingArguments
+
# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
@@ -430,6 +471,9 @@ Register-TabExpansion Script-DbContext @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
about_EntityFrameworkCore
#>
@@ -440,7 +484,9 @@ function Script-DbContext
[string] $Output,
[string] $Context,
[string] $Project,
- [string] $StartupProject)
+ [string] $StartupProject,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
@@ -465,6 +511,7 @@ function Script-DbContext
$params = 'dbcontext', 'script', '--output', $Output
$params += GetParams $Context
+ $params += $RemainingArguments
EF $dteProject $dteStartupProject $params
@@ -512,6 +559,9 @@ Register-TabExpansion Script-Migration @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
Update-Database
about_EntityFrameworkCore
@@ -529,7 +579,9 @@ function Script-Migration
[string] $Output,
[string] $Context,
[string] $Project,
- [string] $StartupProject)
+ [string] $StartupProject,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
@@ -569,6 +621,7 @@ function Script-Migration
}
$params += GetParams $Context
+ $params += $RemainingArguments
EF $dteProject $dteStartupProject $params
@@ -609,6 +662,9 @@ Register-TabExpansion Update-Database @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.
+.PARAMETER RemainingArguments
+ Arguments passed to the application.
+
.LINK
Script-Migration
about_EntityFrameworkCore
@@ -622,7 +678,9 @@ function Update-Database
[string] $Connection,
[string] $Context,
[string] $Project,
- [string] $StartupProject)
+ [string] $StartupProject,
+ [Parameter(ValueFromRemainingArguments = $true)]
+ [string[]] $RemainingArguments)
WarnIfEF6 'Update-Database'
@@ -642,6 +700,7 @@ function Update-Database
}
$params += GetParams $Context
+ $params += $RemainingArguments
EF $dteProject $dteStartupProject $params
}
diff --git a/src/dotnet-ef/RootCommand.cs b/src/dotnet-ef/RootCommand.cs
index b95810d0cbd..f47bd395ef1 100644
--- a/src/dotnet-ef/RootCommand.cs
+++ b/src/dotnet-ef/RootCommand.cs
@@ -53,7 +53,7 @@ public override void Configure(CommandLineApplication command)
_command = command;
}
- protected override int Execute()
+ protected override int Execute(string[] _)
{
var commands = _args.TakeWhile(a => a[0] != '-').ToList();
if (_help.HasValue()
diff --git a/src/ef/AppDomainOperationExecutor.cs b/src/ef/AppDomainOperationExecutor.cs
index cdd7ab4e102..acf58cde203 100644
--- a/src/ef/AppDomainOperationExecutor.cs
+++ b/src/ef/AppDomainOperationExecutor.cs
@@ -24,8 +24,9 @@ public AppDomainOperationExecutor(
string projectDir,
string dataDirectory,
string rootNamespace,
- string language)
- : base(assembly, startupAssembly, projectDir, rootNamespace, language)
+ string language,
+ string[] remainingArguments)
+ : base(assembly, startupAssembly, projectDir, rootNamespace, language, remainingArguments)
{
var info = new AppDomainSetup { ApplicationBase = AppBasePath };
@@ -66,7 +67,8 @@ public AppDomainOperationExecutor(
{ "projectDir", ProjectDirectory },
{ "rootNamespace", RootNamespace },
{ "language", Language },
- { "toolsVersion", ProductInfo.GetVersion() }
+ { "toolsVersion", ProductInfo.GetVersion() },
+ { "remainingArguments", RemainingArguments }
}
},
null,
diff --git a/src/ef/CommandLineUtils/CommandLineApplication.cs b/src/ef/CommandLineUtils/CommandLineApplication.cs
index d3f0eac296d..569f5003d5e 100644
--- a/src/ef/CommandLineUtils/CommandLineApplication.cs
+++ b/src/ef/CommandLineUtils/CommandLineApplication.cs
@@ -27,14 +27,14 @@ private enum ParseOptionResult
// remaining arguments, including the first unexpected argument, will be stored in RemainingArguments property.
private readonly bool _throwOnUnexpectedArg;
- public CommandLineApplication(bool throwOnUnexpectedArg = true)
+ public CommandLineApplication(bool throwOnUnexpectedArg = false)
{
_throwOnUnexpectedArg = throwOnUnexpectedArg;
Options = new List();
Arguments = new List();
Commands = new List();
RemainingArguments = new List();
- Invoke = () => 0;
+ Invoke = (args) => 0;
}
public CommandLineApplication Parent { get; set; }
@@ -48,7 +48,7 @@ public CommandLineApplication(bool throwOnUnexpectedArg = true)
public List Arguments { get; }
public List RemainingArguments { get; }
public bool IsShowingInformation { get; protected set; } // Is showing help or version?
- public Func Invoke { get; set; }
+ public Func Invoke { get; set; }
public Func LongVersionGetter { get; set; }
public Func ShortVersionGetter { get; set; }
public List Commands { get; }
@@ -62,7 +62,7 @@ public CommandLineApplication Command(string name, bool throwOnUnexpectedArg = t
public CommandLineApplication Command(
string name, Action configuration,
- bool throwOnUnexpectedArg = true)
+ bool throwOnUnexpectedArg = false)
{
var command = new CommandLineApplication(throwOnUnexpectedArg) { Name = name, Parent = this };
Commands.Add(command);
@@ -98,9 +98,9 @@ public CommandArgument Argument(string name, string description, Action invoke) => Invoke = invoke;
+ public void OnExecute(Func invoke) => Invoke = invoke;
- public void OnExecute(Func> invoke) => Invoke = () => invoke().Result;
+ public void OnExecute(Func> invoke) => Invoke = (args) => invoke(args).Result;
public int Execute(params string[] args)
{
@@ -158,7 +158,7 @@ public int Execute(params string[] args)
}
}
- return command.Invoke();
+ return command.Invoke(command.RemainingArguments.ToArray());
}
private ParseOptionResult ParseOption(
diff --git a/src/ef/Commands/CommandBase.cs b/src/ef/Commands/CommandBase.cs
index 1bdde78a788..b857de3f665 100644
--- a/src/ef/Commands/CommandBase.cs
+++ b/src/ef/Commands/CommandBase.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using JetBrains.Annotations;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.EntityFrameworkCore.Tools.Properties;
@@ -17,7 +18,7 @@ public virtual void Configure(CommandLineApplication command)
command.HandleResponseFiles = true;
command.OnExecute(
- () =>
+ (args) =>
{
Reporter.IsVerbose = verbose.HasValue();
Reporter.NoColor = noColor.HasValue();
@@ -25,7 +26,7 @@ public virtual void Configure(CommandLineApplication command)
Validate();
- return Execute();
+ return Execute(args);
});
}
@@ -33,7 +34,7 @@ protected virtual void Validate()
{
}
- protected virtual int Execute()
+ protected virtual int Execute([NotNull] string[] args)
=> 0;
}
}
diff --git a/src/ef/Commands/DatabaseDropCommand.cs b/src/ef/Commands/DatabaseDropCommand.cs
index b1b076260de..527ae31ef22 100644
--- a/src/ef/Commands/DatabaseDropCommand.cs
+++ b/src/ef/Commands/DatabaseDropCommand.cs
@@ -9,9 +9,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands
// ReSharper disable once ArrangeTypeModifiers
internal partial class DatabaseDropCommand
{
- protected override int Execute()
+ protected override int Execute(string[] args)
{
- var executor = CreateExecutor();
+ var executor = CreateExecutor(args);
void LogDropCommand(Func