Skip to content

Commit 74e07b5

Browse files
authored
Use DacFx for SQL Server 2022 (#363)
* Use DacFx for SQL Server 2022 Use microsoft.sqlpackage on container * use old default value * Make it optional * add test Co-authored-by: Erik Ejlskov Jensen <[email protected]>
1 parent 3f9c484 commit 74e07b5

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

.github/workflows/main.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,19 @@ jobs:
220220
name: dacpac-package
221221
path: ~/dacpac-package
222222

223-
# Download sqlpackage
224-
- name: download sqlpackage
225-
run: >
226-
curl -L https://go.microsoft.com/fwlink/?linkid=2113331 --output sqlpackage.zip &&
227-
unzip sqlpackage.zip -d ~/sqlpackage &&
228-
chmod a+x ~/sqlpackage/sqlpackage
223+
# Setup .NET SDK
224+
- uses: actions/setup-dotnet@v3
225+
with:
226+
dotnet-version: '6.0.x'
227+
228+
# Install Microsoft.SqlPackage
229+
- name: install microsoft.sqlpackage
230+
run: dotnet tool install --tool-path . microsoft.sqlpackage
229231

230232
# Run sqlpackage
231233
- name: sqlpackage publish
232234
run: >
233-
~/sqlpackage/sqlpackage
235+
sqlpackage
234236
/Action:Publish
235237
/SourceFile:$HOME/dacpac-package/TestProjectWithSDKRef.dacpac
236238
/Properties:IncludeCompositeObjects=True

src/DacpacTool/DacpacTool.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.SqlServer.DACFX" Version="160.6296.0" />
15+
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="161.6374.0" />
1616
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
1717
</ItemGroup>
1818

src/DacpacTool/DeployOptions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.IO;
1+
using System.IO;
22

33
namespace MSBuild.Sdk.SqlProj.DacpacTool
44
{
@@ -13,5 +13,6 @@ public class DeployOptions : BaseOptions
1313
public string[] Property { get; set; }
1414
public string[] SqlCmdVar { get; set; }
1515
public bool RunScriptsFromReferences { get; set; }
16+
public bool Encrypt { get; set; } = false;
1617
}
1718
}

src/DacpacTool/PackageDeployer.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using Microsoft.Data.SqlClient;
@@ -55,6 +55,12 @@ public void UseWindowsAuthentication()
5555
_console.WriteLine("Using Windows Authentication");
5656
}
5757

58+
public void UseEncrypt(bool encrypt)
59+
{
60+
ConnectionStringBuilder.Encrypt = encrypt;
61+
_console.WriteLine($"Using encrypt: {encrypt}");
62+
}
63+
5864
public void SetSqlCmdVariable(string key, string value)
5965
{
6066
if (string.IsNullOrWhiteSpace(key))

src/DacpacTool/Program.cs

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static async Task<int> Main(string[] args)
6262
new Option<string[]>(new string[] { "--property", "-p" }, "Properties used to control the deployment"),
6363
new Option<string[]>(new string[] { "--sqlcmdvar", "-sc" }, "SqlCmdVariable(s) and their associated values, separated by an equals sign."),
6464
new Option<bool>(new string[] { "--runScriptsFromReferences", "-sff" }, "Whether to run pre- and postdeployment scripts from references"),
65+
new Option<bool>(new string[] { "--encrypt", "-e" }, "Encrypt the connection, defaults to false"),
6566
#if DEBUG
6667
new Option<bool>(new string[] { "--debug" }, "Waits for a debugger to attach")
6768
#endif
@@ -229,6 +230,8 @@ private static int DeployDacpac(DeployOptions options)
229230
deployer.SetDeployProperties(options.Property);
230231
}
231232

233+
deployer.UseEncrypt(options.Encrypt);
234+
232235
if (options.SqlCmdVar != null)
233236
{
234237
foreach (var sqlCmdVar in options.SqlCmdVar)

test/DacpacTool.Tests/PackageDeployerTests.cs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using Microsoft.SqlServer.Dac;
44
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -53,6 +53,32 @@ public void UseWindowsAuthentication()
5353
packageDeployer.ConnectionStringBuilder.IntegratedSecurity.ShouldBeTrue();
5454
}
5555

56+
[TestMethod]
57+
public void UseEncrypt()
58+
{
59+
// Arrange
60+
var packageDeployer = new PackageDeployer(_console);
61+
62+
// Act
63+
packageDeployer.UseEncrypt(true);
64+
65+
// Assert
66+
packageDeployer.ConnectionStringBuilder.Encrypt.ShouldBe(Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Mandatory);
67+
}
68+
69+
[TestMethod]
70+
public void EncryptDefault()
71+
{
72+
// Arrange
73+
var packageDeployer = new PackageDeployer(_console);
74+
75+
// Act
76+
packageDeployer.UseEncrypt(false);
77+
78+
// Assert
79+
packageDeployer.ConnectionStringBuilder.Encrypt.ShouldBe(Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Optional);
80+
}
81+
5682
[TestMethod]
5783
public void UseSqlServerAuthenticationNoPasswordPrompts()
5884
{

0 commit comments

Comments
 (0)