diff --git a/Build/build-tasks.ps1 b/Build/build-tasks.ps1
index 81f7f08c..29fcbbb3 100644
--- a/Build/build-tasks.ps1
+++ b/Build/build-tasks.ps1
@@ -3,7 +3,6 @@ Include ".\build-scripts.ps1"
Task default -Depends Initialize, Clean, Build, Pack, UnitTest, Test
Task Pack -Depends PackGlobalTool, PackNet452, PackChoco, PackManualDownload
Task UnitTest -Depends InitializeTests `
- , UnitTest452 `
, UnitTest472 `
, UnitTestcore22 `
, UnitTestcore31 `
@@ -159,7 +158,7 @@ Task PackManualDownload {
Task InitializeTests {
Copy-Item -Path (Join-Path $sourceDir "SqlDatabase.Test\IntegrationTests") -Destination $binDir -Force -Recurse
- Copy-Item -Path (Join-Path $binDir "Tests\net452\2.1_2.2.*") -Destination (Join-Path $binDir "IntegrationTests\Upgrade") -Force -Recurse
+ Copy-Item -Path (Join-Path $binDir "Tests\net472\2.1_2.2.*") -Destination (Join-Path $binDir "IntegrationTests\Upgrade") -Force -Recurse
# fix unix line endings
$test = $moduleIntegrationTests + ":/test"
@@ -171,10 +170,6 @@ Task InitializeTests {
}
}
-Task UnitTest452 {
- Test-Unit "net452"
-}
-
Task UnitTest472 {
Test-Unit "net472"
}
@@ -240,7 +235,7 @@ Task TestPowerShellCore710 {
}
Task TestPowerShellCore720 {
- Test-PowerShellCore "mcr.microsoft.com/powershell:7.2.0-preview.1-ubuntu-20.04"
+ Test-PowerShellCore "mcr.microsoft.com/powershell:7.2.0-preview.2-ubuntu-20.04"
}
Task TestPublishModule {
diff --git a/LICENSE.md b/LICENSE.md
index 05145d1d..2aefa8f2 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2018-2020 max-ieremenko
+Copyright (c) 2018-2021 max-ieremenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Sources/Directory.Build.props b/Sources/Directory.Build.props
index de37e3b9..272cf166 100644
--- a/Sources/Directory.Build.props
+++ b/Sources/Directory.Build.props
@@ -11,7 +11,7 @@
-
+
diff --git a/Sources/GlobalAssemblyInfo.cs b/Sources/GlobalAssemblyInfo.cs
index 85b63946..e93db543 100644
--- a/Sources/GlobalAssemblyInfo.cs
+++ b/Sources/GlobalAssemblyInfo.cs
@@ -9,5 +9,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
-[assembly: AssemblyVersion("2.1.2.0")]
-[assembly: AssemblyFileVersion("2.1.2.0")]
+[assembly: AssemblyVersion("2.1.3.0")]
+[assembly: AssemblyFileVersion("2.1.3.0")]
diff --git a/Sources/SqlDatabase.Package/choco/sqldatabase.nuspec b/Sources/SqlDatabase.Package/choco/sqldatabase.nuspec
index 3449e5f8..841c3cf2 100644
--- a/Sources/SqlDatabase.Package/choco/sqldatabase.nuspec
+++ b/Sources/SqlDatabase.Package/choco/sqldatabase.nuspec
@@ -18,7 +18,7 @@
SqlDatabase is a tool for SQL Server, allows to execute scripts, database migrations and export data.
Requires Powershell Core 6.1+ or PowerShell Desktop 5.1.
https://github.com/max-ieremenko/SqlDatabase/releases
- (C) 2018-2020 Max Ieremenko.
+ (C) 2018-2021 Max Ieremenko.
sqlserver sqlcmd migration-tool c-sharp command-line-tool miration-step sql-script sql-database database-migrations export-data
diff --git a/Sources/SqlDatabase.Package/nuget/package.nuspec b/Sources/SqlDatabase.Package/nuget/package.nuspec
index 88af059f..97ecfcc7 100644
--- a/Sources/SqlDatabase.Package/nuget/package.nuspec
+++ b/Sources/SqlDatabase.Package/nuget/package.nuspec
@@ -14,7 +14,7 @@
Command-line tool and PowerShell module for SQL Server.
SqlDatabase is a tool for SQL Server, allows to execute scripts, database migrations and export data.
https://github.com/max-ieremenko/SqlDatabase/releases
- (C) 2018-2020 Max Ieremenko.
+ (C) 2018-2021 Max Ieremenko.
sqlserver sqlcmd migration-tool c-sharp command-line-tool miration-step sql-script sql-database database-migrations export-data
diff --git a/Sources/SqlDatabase.PowerShell.Test/CreateCmdLetTest.cs b/Sources/SqlDatabase.PowerShell.Test/CreateCmdLetTest.cs
index bfb37bdc..716d8da4 100644
--- a/Sources/SqlDatabase.PowerShell.Test/CreateCmdLetTest.cs
+++ b/Sources/SqlDatabase.PowerShell.Test/CreateCmdLetTest.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using System.IO;
+using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
@@ -29,8 +30,16 @@ public void BuildCommandLine(string commandName)
commandLine.Command.ShouldBe(CommandLineFactory.CommandCreate);
commandLine.Connection.ShouldBe("connection string");
- commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });
- commandLine.ConfigurationFile.ShouldBe("app.config");
+
+ commandLine.Scripts.Count.ShouldBe(2);
+ Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
+ Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");
+
+ Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
+ Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");
+
commandLine.WhatIf.ShouldBeTrue();
commandLine.Variables.Keys.ShouldBe(new[] { "x", "y" });
@@ -53,12 +62,16 @@ public void BuildPipeCommandLine(string commandName)
commandLines[0].Command.ShouldBe(CommandLineFactory.CommandCreate);
commandLines[0].Connection.ShouldBe("connection string");
- commandLines[0].Scripts.ShouldBe(new[] { "file 1" });
+ commandLines[0].Scripts.Count.ShouldBe(1);
+ Path.IsPathRooted(commandLines[0].Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLines[0].Scripts[0]).ShouldBe("file 1");
commandLines[0].InLineScript.Count.ShouldBe(0);
commandLines[1].Command.ShouldBe(CommandLineFactory.CommandCreate);
commandLines[1].Connection.ShouldBe("connection string");
- commandLines[1].Scripts.ShouldBe(new[] { "file 2" });
+ commandLines[1].Scripts.Count.ShouldBe(1);
+ Path.IsPathRooted(commandLines[1].Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLines[1].Scripts[0]).ShouldBe("file 2");
commandLines[1].InLineScript.Count.ShouldBe(0);
}
}
diff --git a/Sources/SqlDatabase.PowerShell.Test/ExecuteCmdLetTest.cs b/Sources/SqlDatabase.PowerShell.Test/ExecuteCmdLetTest.cs
index fcd78bfb..bc3bdea5 100644
--- a/Sources/SqlDatabase.PowerShell.Test/ExecuteCmdLetTest.cs
+++ b/Sources/SqlDatabase.PowerShell.Test/ExecuteCmdLetTest.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using System.IO;
+using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
@@ -31,10 +32,19 @@ public void BuildCommandLine(string commandName)
commandLine.Command.ShouldBe(CommandLineFactory.CommandExecute);
commandLine.Connection.ShouldBe("connection string");
- commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });
+
+ commandLine.Scripts.Count.ShouldBe(2);
+ Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
+ Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");
+
commandLine.InLineScript.ShouldBe(new[] { "sql text 1", "sql text 2" });
commandLine.Transaction.ShouldBe(TransactionMode.PerStep);
- commandLine.ConfigurationFile.ShouldBe("app.config");
+
+ Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
+ Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");
+
commandLine.WhatIf.ShouldBeTrue();
commandLine.Variables.Keys.ShouldBe(new[] { "x", "y" });
@@ -57,12 +67,16 @@ public void BuildPipeCommandLine(string commandName)
commandLines[0].Command.ShouldBe(CommandLineFactory.CommandExecute);
commandLines[0].Connection.ShouldBe("connection string");
- commandLines[0].Scripts.ShouldBe(new[] { "file 1" });
+ commandLines[0].Scripts.Count.ShouldBe(1);
+ Path.IsPathRooted(commandLines[0].Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLines[0].Scripts[0]).ShouldBe("file 1");
commandLines[0].InLineScript.Count.ShouldBe(0);
commandLines[1].Command.ShouldBe(CommandLineFactory.CommandExecute);
commandLines[1].Connection.ShouldBe("connection string");
- commandLines[1].Scripts.ShouldBe(new[] { "file 2" });
+ commandLines[1].Scripts.Count.ShouldBe(1);
+ Path.IsPathRooted(commandLines[1].Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLines[1].Scripts[0]).ShouldBe("file 2");
commandLines[1].InLineScript.Count.ShouldBe(0);
}
}
diff --git a/Sources/SqlDatabase.PowerShell.Test/ExportCmdLetTest.cs b/Sources/SqlDatabase.PowerShell.Test/ExportCmdLetTest.cs
index 5388be2e..2ca17d61 100644
--- a/Sources/SqlDatabase.PowerShell.Test/ExportCmdLetTest.cs
+++ b/Sources/SqlDatabase.PowerShell.Test/ExportCmdLetTest.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using System.IO;
+using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
@@ -29,11 +30,19 @@ public void BuildCommandLine()
commandLine.Command.ShouldBe(CommandLineFactory.CommandExport);
commandLine.Connection.ShouldBe("connection string");
- commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });
+
+ commandLine.Scripts.Count.ShouldBe(2);
+ Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
+ Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");
+
commandLine.InLineScript.ShouldBe(new[] { "sql text 1", "sql text 2" });
commandLine.ExportToFile.ShouldBe("to file");
commandLine.ExportToTable.ShouldBe("to table");
- commandLine.ConfigurationFile.ShouldBe("app.config");
+
+ Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
+ Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");
commandLine.Variables.Keys.ShouldBe(new[] { "x", "y" });
commandLine.Variables["x"].ShouldBe("1");
diff --git a/Sources/SqlDatabase.PowerShell.Test/SqlDatabase.PowerShell.Test.csproj b/Sources/SqlDatabase.PowerShell.Test/SqlDatabase.PowerShell.Test.csproj
index 004a8b67..d3b06cda 100644
--- a/Sources/SqlDatabase.PowerShell.Test/SqlDatabase.PowerShell.Test.csproj
+++ b/Sources/SqlDatabase.PowerShell.Test/SqlDatabase.PowerShell.Test.csproj
@@ -7,15 +7,15 @@
-
-
+
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/Sources/SqlDatabase.PowerShell.Test/SqlDatabaseProgramFactoryTest.cs b/Sources/SqlDatabase.PowerShell.Test/SqlDatabaseProgramFactoryTest.cs
index 2ddad231..ec8fd23b 100644
--- a/Sources/SqlDatabase.PowerShell.Test/SqlDatabaseProgramFactoryTest.cs
+++ b/Sources/SqlDatabase.PowerShell.Test/SqlDatabaseProgramFactoryTest.cs
@@ -23,7 +23,7 @@ public void CreateProgram(string psEdition, Type expected)
var owner = new Mock(MockBehavior.Strict);
- var actual = SqlDatabaseProgramFactory.CreateProgram(psVersionTable, owner.Object);
+ var actual = SqlDatabaseProgramFactory.CreateProgram(new PSVersionTable(psVersionTable), owner.Object);
actual.ShouldBeOfType(expected);
}
diff --git a/Sources/SqlDatabase.PowerShell.Test/UpgradeCmdLetTest.cs b/Sources/SqlDatabase.PowerShell.Test/UpgradeCmdLetTest.cs
index 8b6ce20c..bb0320ec 100644
--- a/Sources/SqlDatabase.PowerShell.Test/UpgradeCmdLetTest.cs
+++ b/Sources/SqlDatabase.PowerShell.Test/UpgradeCmdLetTest.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using System.IO;
+using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
@@ -31,9 +32,18 @@ public void BuildCommandLine(string commandName)
commandLine.Command.ShouldBe(CommandLineFactory.CommandUpgrade);
commandLine.Connection.ShouldBe("connection string");
- commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });
+
+ commandLine.Scripts.Count.ShouldBe(2);
+ Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
+ Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
+ Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");
+
commandLine.Transaction.ShouldBe(TransactionMode.PerStep);
- commandLine.ConfigurationFile.ShouldBe("app.config");
+
+ Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
+ Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");
+
commandLine.WhatIf.ShouldBeTrue();
commandLine.FolderAsModuleName.ShouldBeTrue();
@@ -57,12 +67,16 @@ public void BuildPipeCommandLine(string commandName)
commandLines[0].Command.ShouldBe(CommandLineFactory.CommandUpgrade);
commandLines[0].Connection.ShouldBe("connection string");
- commandLines[0].Scripts.ShouldBe(new[] { "file 1" });
+ commandLines[0].Scripts.Count.ShouldBe(1);
+ Path.IsPathRooted(commandLines[0].Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLines[0].Scripts[0]).ShouldBe("file 1");
commandLines[0].InLineScript.Count.ShouldBe(0);
commandLines[1].Command.ShouldBe(CommandLineFactory.CommandUpgrade);
commandLines[1].Connection.ShouldBe("connection string");
- commandLines[1].Scripts.ShouldBe(new[] { "file 2" });
+ commandLines[1].Scripts.Count.ShouldBe(1);
+ Path.IsPathRooted(commandLines[1].Scripts[0]).ShouldBeTrue();
+ Path.GetFileName(commandLines[1].Scripts[0]).ShouldBe("file 2");
commandLines[1].InLineScript.Count.ShouldBe(0);
}
}
diff --git a/Sources/SqlDatabase.PowerShell/CmdletExtensions.cs b/Sources/SqlDatabase.PowerShell/CmdletExtensions.cs
new file mode 100644
index 00000000..f31aa3a5
--- /dev/null
+++ b/Sources/SqlDatabase.PowerShell/CmdletExtensions.cs
@@ -0,0 +1,55 @@
+using System;
+using System.IO;
+using System.Management.Automation;
+using SqlDatabase.Configuration;
+
+namespace SqlDatabase.PowerShell
+{
+ internal static class CmdletExtensions
+ {
+ public static string GetWorkingDirectory(this PSCmdlet cmdlet)
+ {
+ var root = cmdlet.MyInvocation.PSScriptRoot;
+ if (string.IsNullOrEmpty(root))
+ {
+ root = cmdlet.CurrentProviderLocation("FileSystem").ProviderPath;
+ }
+
+ return root;
+ }
+
+ public static string RootPath(this PSCmdlet cmdlet, string path)
+ {
+ if (string.IsNullOrEmpty(path) || Path.IsPathRooted(path))
+ {
+ return path;
+ }
+
+ return Path.Combine(GetWorkingDirectory(cmdlet), path);
+ }
+
+ public static bool TryGetPSVersionTable(this PSCmdlet cmdlet, out PSVersionTable value)
+ {
+ var psVersionTable = cmdlet.GetVariableValue("PSVersionTable");
+ if (psVersionTable == null)
+ {
+ value = default;
+ return false;
+ }
+
+ value = new PSVersionTable(psVersionTable);
+ return true;
+ }
+
+ public static void AppendFrom(this PSCmdlet cmdlet, string[] from, GenericCommandLineBuilder target)
+ {
+ if (from != null)
+ {
+ for (var i = 0; i < from.Length; i++)
+ {
+ target.SetScripts(cmdlet.RootPath(from[i]));
+ }
+ }
+ }
+ }
+}
diff --git a/Sources/SqlDatabase.PowerShell/CreateCmdLet.cs b/Sources/SqlDatabase.PowerShell/CreateCmdLet.cs
index be373a3d..eeabf668 100644
--- a/Sources/SqlDatabase.PowerShell/CreateCmdLet.cs
+++ b/Sources/SqlDatabase.PowerShell/CreateCmdLet.cs
@@ -25,16 +25,10 @@ public CreateCmdLet()
internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
{
- if (From != null && From.Length > 0)
- {
- foreach (var from in From)
- {
- cmd.SetScripts(from);
- }
- }
+ this.AppendFrom(From, cmd);
cmd
- .SetConfigurationFile(Configuration)
+ .SetConfigurationFile(this.RootPath(Configuration))
.SetWhatIf(WhatIf);
}
}
diff --git a/Sources/SqlDatabase.PowerShell/ExecuteCmdLet.cs b/Sources/SqlDatabase.PowerShell/ExecuteCmdLet.cs
index 2b154a31..73ec7263 100644
--- a/Sources/SqlDatabase.PowerShell/ExecuteCmdLet.cs
+++ b/Sources/SqlDatabase.PowerShell/ExecuteCmdLet.cs
@@ -34,13 +34,7 @@ public ExecuteCmdLet()
internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
{
- if (From != null && From.Length > 0)
- {
- foreach (var from in From)
- {
- cmd.SetScripts(from);
- }
- }
+ this.AppendFrom(From, cmd);
if (FromSql != null && FromSql.Length > 0)
{
@@ -52,7 +46,7 @@ internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
cmd
.SetTransaction(Transaction)
- .SetConfigurationFile(Configuration)
+ .SetConfigurationFile(this.RootPath(Configuration))
.SetWhatIf(WhatIf);
}
}
diff --git a/Sources/SqlDatabase.PowerShell/ExportCmdLet.cs b/Sources/SqlDatabase.PowerShell/ExportCmdLet.cs
index 3444def5..b81a5526 100644
--- a/Sources/SqlDatabase.PowerShell/ExportCmdLet.cs
+++ b/Sources/SqlDatabase.PowerShell/ExportCmdLet.cs
@@ -31,13 +31,7 @@ public ExportCmdLet()
internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
{
- if (From != null && From.Length > 0)
- {
- foreach (var from in From)
- {
- cmd.SetScripts(from);
- }
- }
+ this.AppendFrom(From, cmd);
if (FromSql != null && FromSql.Length > 0)
{
@@ -48,7 +42,7 @@ internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
}
cmd
- .SetConfigurationFile(Configuration)
+ .SetConfigurationFile(this.RootPath(Configuration))
.SetExportToTable(ToTable)
.SetExportToFile(ToFile);
}
diff --git a/Sources/SqlDatabase.PowerShell/InfoCmdLet.cs b/Sources/SqlDatabase.PowerShell/InfoCmdLet.cs
index ef23d392..41a603ba 100644
--- a/Sources/SqlDatabase.PowerShell/InfoCmdLet.cs
+++ b/Sources/SqlDatabase.PowerShell/InfoCmdLet.cs
@@ -12,12 +12,19 @@ protected override void ProcessRecord()
{
var assembly = GetType().Assembly;
+ this.TryGetPSVersionTable(out var psVersionTable);
+
WriteObject(new
{
+ psVersionTable.PSEdition,
+ psVersionTable.PSVersion,
Version = assembly.GetName().Version,
RuntimeInformation.FrameworkDescription,
RuntimeInformation.OSDescription,
+ RuntimeInformation.OSArchitecture,
+ RuntimeInformation.ProcessArchitecture,
Location = Path.GetDirectoryName(assembly.Location),
+ WorkingDirectory = this.GetWorkingDirectory(),
DefaultConfigurationFile = ConfigurationManager.ResolveDefaultConfigurationFile()
});
}
diff --git a/Sources/SqlDatabase.PowerShell/PSVersionTable.cs b/Sources/SqlDatabase.PowerShell/PSVersionTable.cs
new file mode 100644
index 00000000..8c03742a
--- /dev/null
+++ b/Sources/SqlDatabase.PowerShell/PSVersionTable.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections;
+
+namespace SqlDatabase.PowerShell
+{
+ internal readonly ref struct PSVersionTable
+ {
+ public PSVersionTable(object value)
+ {
+ PSEdition = null;
+ PSVersion = null;
+
+ // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_editions?view=powershell-7
+ var source = (IEnumerable)value;
+ foreach (DictionaryEntry entry in source)
+ {
+ var key = (string)entry.Key;
+ if ("PSEdition".Equals(key, StringComparison.OrdinalIgnoreCase))
+ {
+ PSEdition = Convert.ToString(entry.Value);
+ }
+ else if ("PSVersion".Equals(key, StringComparison.OrdinalIgnoreCase))
+ {
+ PSVersion = Convert.ToString(entry.Value);
+ }
+ }
+ }
+
+ public string PSEdition { get; }
+
+ public string PSVersion { get; }
+ }
+}
diff --git a/Sources/SqlDatabase.PowerShell/SqlDatabase.psd1 b/Sources/SqlDatabase.PowerShell/SqlDatabase.psd1
index 530ee3a0..0813d227 100644
Binary files a/Sources/SqlDatabase.PowerShell/SqlDatabase.psd1 and b/Sources/SqlDatabase.PowerShell/SqlDatabase.psd1 differ
diff --git a/Sources/SqlDatabase.PowerShell/SqlDatabaseCmdlet.cs b/Sources/SqlDatabase.PowerShell/SqlDatabaseCmdlet.cs
index 20f5741b..55781de4 100644
--- a/Sources/SqlDatabase.PowerShell/SqlDatabaseCmdlet.cs
+++ b/Sources/SqlDatabase.PowerShell/SqlDatabaseCmdlet.cs
@@ -45,9 +45,9 @@ protected sealed override void ProcessRecord()
if (Var != null && Var.Length > 0)
{
- foreach (var value in Var)
+ for (var i = 0; i < Var.Length; i++)
{
- cmd.SetVariable(value);
+ cmd.SetVariable(Var[i]);
}
}
@@ -66,8 +66,7 @@ private ISqlDatabaseProgram ResolveProgram()
return Program;
}
- var psVersionTable = (IEnumerable)GetVariableValue("PSVersionTable");
- if (psVersionTable == null)
+ if (!this.TryGetPSVersionTable(out var psVersionTable))
{
throw new PlatformNotSupportedException("$PSVersionTable is not defined.");
}
diff --git a/Sources/SqlDatabase.PowerShell/SqlDatabaseProgramFactory.cs b/Sources/SqlDatabase.PowerShell/SqlDatabaseProgramFactory.cs
index 1e45b5b3..75a46540 100644
--- a/Sources/SqlDatabase.PowerShell/SqlDatabaseProgramFactory.cs
+++ b/Sources/SqlDatabase.PowerShell/SqlDatabaseProgramFactory.cs
@@ -1,21 +1,13 @@
using System;
-using System.Collections;
-using System.Linq;
namespace SqlDatabase.PowerShell
{
internal static class SqlDatabaseProgramFactory
{
- public static ISqlDatabaseProgram CreateProgram(IEnumerable psVersionTable, ICmdlet owner)
+ public static ISqlDatabaseProgram CreateProgram(PSVersionTable psVersionTable, ICmdlet owner)
{
- // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_editions?view=powershell-7
- var psEdition = (string)psVersionTable
- .Cast()
- .FirstOrDefault(i => "PSEdition".Equals((string)i.Key, StringComparison.OrdinalIgnoreCase))
- .Value;
-
// In PowerShell 4 and below, this variable does not exist
- if (string.IsNullOrEmpty(psEdition) || "Desktop".Equals(psEdition, StringComparison.OrdinalIgnoreCase))
+ if (string.IsNullOrEmpty(psVersionTable.PSEdition) || "Desktop".Equals(psVersionTable.PSEdition, StringComparison.OrdinalIgnoreCase))
{
return new SqlDatabaseProgramNet452(owner);
}
diff --git a/Sources/SqlDatabase.PowerShell/UpgradeCmdLet.cs b/Sources/SqlDatabase.PowerShell/UpgradeCmdLet.cs
index fed50746..23641a15 100644
--- a/Sources/SqlDatabase.PowerShell/UpgradeCmdLet.cs
+++ b/Sources/SqlDatabase.PowerShell/UpgradeCmdLet.cs
@@ -32,16 +32,10 @@ public UpgradeCmdLet()
internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
{
- if (From != null && From.Length > 0)
- {
- foreach (var from in From)
- {
- cmd.SetScripts(from);
- }
- }
+ this.AppendFrom(From, cmd);
cmd
- .SetConfigurationFile(Configuration)
+ .SetConfigurationFile(this.RootPath(Configuration))
.SetTransaction(Transaction)
.SetWhatIf(WhatIf)
.SetFolderAsModuleName(FolderAsModuleName);
diff --git a/Sources/SqlDatabase.Test/SqlDatabase.Test.csproj b/Sources/SqlDatabase.Test/SqlDatabase.Test.csproj
index 34a28ade..d35c565d 100644
--- a/Sources/SqlDatabase.Test/SqlDatabase.Test.csproj
+++ b/Sources/SqlDatabase.Test/SqlDatabase.Test.csproj
@@ -1,7 +1,7 @@
- net452;netcoreapp2.2;netcoreapp3.1;net5.0
+ net472;netcoreapp2.2;netcoreapp3.1;net5.0
SqlDatabase
NU1702
..\..\bin\Tests
@@ -52,14 +52,13 @@
-
-
-
+
+
+
-
+
-
-
+
diff --git a/Sources/SqlDatabase/SqlDatabase.csproj b/Sources/SqlDatabase/SqlDatabase.csproj
index 3bfe4840..60166376 100644
--- a/Sources/SqlDatabase/SqlDatabase.csproj
+++ b/Sources/SqlDatabase/SqlDatabase.csproj
@@ -27,7 +27,7 @@
https://github.com/max-ieremenko/SqlDatabase/raw/master/icon-32.png
icon-32.png
MIT
- (C) 2018-2020 Max Ieremenko.
+ (C) 2018-2021 Max Ieremenko.
git
sqlserver sqlcmd migration-tool c-sharp command-line-tool miration-step sql-script sql-database database-migrations export-data