Skip to content

Commit 953c434

Browse files
committed
Add a "runtime" option
1 parent 383b2a4 commit 953c434

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

src/Migrator.EF6.Tools/CommonConfiguration.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public CommonConfiguration(CommandLineApplication command)
1717
public CommandOption ConnectionString { get; set; }
1818
public CommandOption ProviderName { get; set; }
1919
public CommandOption Context { get; set; }
20+
public CommandOption Runtime { get; set; }
2021

2122
public CommonConfiguration AddConnectionStringOption()
2223
{
@@ -34,6 +35,13 @@ public CommonConfiguration AddProviderNameOption()
3435
return this;
3536
}
3637

38+
public CommonConfiguration AddContextAndRuntimeOptions()
39+
{
40+
return
41+
AddContextOption()
42+
.AddRuntimeOption();
43+
}
44+
3745
public CommonConfiguration AddContextOption()
3846
{
3947
Context = _command.Option(
@@ -42,6 +50,14 @@ public CommonConfiguration AddContextOption()
4250
return this;
4351
}
4452

53+
public CommonConfiguration AddRuntimeOption()
54+
{
55+
Runtime = _command.Option(
56+
"-r|--runtime <runtime>",
57+
"The runtime to use.");
58+
return this;
59+
}
60+
4561
public Executor CreateExecutor()
4662
{
4763
return new Executor(

src/Migrator.EF6.Tools/DatabaseCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private void ConfigureInternal(CommandLineApplication command)
3232
var common = Common(update)
3333
.AddConnectionStringOption()
3434
.AddProviderNameOption()
35-
.AddContextOption();
35+
.AddContextAndRuntimeOptions();
3636

3737
var force = update.Option(
3838
"--force",
@@ -55,7 +55,7 @@ private void ConfigureInternal(CommandLineApplication command)
5555
var common = Common(truncate)
5656
.AddConnectionStringOption()
5757
.AddProviderNameOption()
58-
.AddContextOption();
58+
.AddContextAndRuntimeOptions();
5959

6060
truncate.OnExecute(() =>
6161
{
@@ -73,7 +73,7 @@ private void ConfigureInternal(CommandLineApplication command)
7373
var common = Common(recreate)
7474
.AddConnectionStringOption()
7575
.AddProviderNameOption()
76-
.AddContextOption();
76+
.AddContextAndRuntimeOptions();
7777

7878
recreate.OnExecute(() =>
7979
{

src/Migrator.EF6.Tools/MigrationsCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private void ConfigureInternal(CommandLineApplication command)
3030
"The directory (and sub-namespace) to use. If omitted, \"Migrations\" is used. Relative paths are relative the directory in which the command is executed.");
3131

3232
var common = Common(enable)
33-
.AddContextOption();
33+
.AddContextAndRuntimeOptions();
3434

3535
enable.OnExecute(() =>
3636
{
@@ -52,7 +52,7 @@ private void ConfigureInternal(CommandLineApplication command)
5252
var common = Common(add)
5353
.AddConnectionStringOption()
5454
.AddProviderNameOption()
55-
.AddContextOption();
55+
.AddContextAndRuntimeOptions();
5656

5757
var outputDir = add.Option(
5858
"-o|--output-dir <path>",
@@ -96,7 +96,7 @@ private void ConfigureInternal(CommandLineApplication command)
9696
var common = Common(script)
9797
.AddConnectionStringOption()
9898
.AddProviderNameOption()
99-
.AddContextOption();
99+
.AddContextAndRuntimeOptions();
100100

101101
var output = script.Option(
102102
"-o|--output <file>",
@@ -127,7 +127,7 @@ private void ConfigureInternal(CommandLineApplication command)
127127
var common = Common(list)
128128
.AddConnectionStringOption()
129129
.AddProviderNameOption()
130-
.AddContextOption();
130+
.AddContextAndRuntimeOptions();
131131

132132
list.OnExecute(() =>
133133
{

src/Migrator.EF6.Tools/Program.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ private static void Dispatch(string[] args)
5959
}
6060
Console.WriteLine();
6161

62-
var toolPath = Path.Combine(projectFile.ProjectDirectory, "bin", "Debug", framework.TFM, "dotnet-ef.exe");
63-
var assemblyPath = Path.Combine(projectFile.ProjectDirectory, "bin", "Debug", framework.TFM, projectFile.Name + ".exe");
62+
var runtime = GetRuntimeOption(args) ?? string.Empty;
63+
var toolPath = Path.Combine(projectFile.ProjectDirectory, "bin", "Debug", framework.TFM, runtime, "dotnet-ef.exe");
64+
var assemblyPath = Path.Combine(projectFile.ProjectDirectory, "bin", "Debug", framework.TFM, runtime, projectFile.Name + ".exe");
6465

6566
var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand(
6667
toolPath,
@@ -86,6 +87,23 @@ private static void Dispatch(string[] args)
8687
}
8788
}
8889

90+
private static string GetRuntimeOption(string[] args)
91+
{
92+
var argsList = args.ToList();
93+
var index = argsList.IndexOf("--runtime");
94+
if (index < 0)
95+
{
96+
index = argsList.IndexOf("-r");
97+
}
98+
99+
if (index < 0 || index + 1 >= args.Length)
100+
{
101+
return null;
102+
}
103+
104+
return args[index + 1];
105+
}
106+
89107
private static bool TryResolveFramework(
90108
IEnumerable<TargetNuGetFramework> availableFrameworks,
91109
out TargetNuGetFramework resolvedFramework)

0 commit comments

Comments
 (0)