Skip to content

Commit

Permalink
Add support for publishing a project to a SQL Server (#33)
Browse files Browse the repository at this point in the history
This adds the possibility to run `dotnet publish` on a project that uses `MSBuild.Sdk.SqlProj` in order to deploy the database to a local SQL Server instance.
  • Loading branch information
jmezach authored Aug 9, 2020
1 parent 59ae058 commit a02bfa8
Show file tree
Hide file tree
Showing 29 changed files with 1,089 additions and 99 deletions.
101 changes: 90 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- uses: actions/setup-dotnet@v1

# Install .NET Core SDK
# TOOO: Remove this workaround once https://github.com/actions/setup-dotnet/issues/25 gets fixed
- name: Setup .NET Core
uses: coderpatros/setup-dotnet@sxs
with:
dotnet-version: '3.1.102'
dotnet-version: 2.1.808,3.1.302

# Install Nerdbank.GitVersioning
- name: install nbgv
Expand All @@ -36,15 +40,15 @@ jobs:
run: ./nbgv cloud -p ./src/MSBuild.Sdk.SqlProj/ --all-vars

# Build command line tool
- name: dotnet build
run: dotnet build ./src/BuildDacpac/BuildDacpac.csproj -c Release
- name: dotnet build DacpacTool
run: dotnet build ./src/DacpacTool/DacpacTool.csproj -c Release

# Run tests for command line tool
- name: dotnet test
run: dotnet test ./test/BuildDacpac.Tests/BuildDacpac.Tests.csproj -c Release
run: dotnet test ./test/DacpacTool.Tests/DacpacTool.Tests.csproj -c Release

# Run build for SDK package
- name: dotnet build
- name: dotnet build SDK
run: dotnet build ./src/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj.csproj -c Release

# Ensure that test project builds
Expand Down Expand Up @@ -80,7 +84,7 @@ jobs:
strategy:
matrix:
os: [ "ubuntu-18.04", "macos-10.15", "windows-2019" ]
dotnet: [ '2.1.804', '2.2.207', '3.1.102' ]
dotnet: [ '2.1.808', '3.1.302' ]
fail-fast: false

steps:
Expand Down Expand Up @@ -138,8 +142,8 @@ jobs:
name: binary-log-${{ matrix.os }}-${{ matrix.dotnet }}
path: ./msbuild.binlog

# Attempt to deploy the resulting dacpac's to a SQL Server instance running in a container
deploy:
# Attempt to deploy the resulting dacpac's to a SQL Server instance running in a container using SqlPackage.exe
deploy-sqlpackage:
runs-on: ubuntu-18.04
needs: test
services:
Expand All @@ -150,6 +154,12 @@ jobs:
SA_PASSWORD: JdMsKZPBBA8kVFXVrj8d
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'JdMsKZPBBA8kVFXVrj8d' -Q 'SELECT 1' || exit 1"
--health-interval 10s
--health-timeout 3s
--health-retries 10
--health-start-period 10s
steps:
# Download artifacts
- name: download-artifact
Expand Down Expand Up @@ -182,16 +192,85 @@ jobs:
if: failure()
uses: jwalton/gh-docker-logs@v1

# Attempt to deploy a project to a SQL Server instance running in a container using dotnet publish
deploy-publish:
runs-on: ubuntu-18.04
needs: test
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: JdMsKZPBBA8kVFXVrj8d
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'JdMsKZPBBA8kVFXVrj8d' -Q 'SELECT 1' || exit 1"
--health-interval 10s
--health-timeout 3s
--health-retries 10
--health-start-period 10s
steps:
# Fetch sources
- uses: actions/checkout@v2
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

# Download artifact
- name: download-artifact
uses: actions/download-artifact@v1
with:
name: nuget-packages
path: test/TestProjectWithSDKRef/nuget-packages

# Setup .NET SDK
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.302'

# Install Nerdbank.GitVersioning
- name: install nbgv
run: dotnet tool install --tool-path . nbgv

# Set version
- name: set version
run: ./nbgv cloud -p ./src/MSBuild.Sdk.SqlProj/ --all-vars
id: nbgv

# Replace tokens
- uses: cschleiden/replace-tokens@v1
name: replace tokens
with:
files: 'test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj'

# Publish the project
- name: publish project
run: dotnet publish ./test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj /p:TargetUser=sa /p:TargetPassword=JdMsKZPBBA8kVFXVrj8d /bl

# Upload binary log
- name: upload
uses: actions/upload-artifact@v1
with:
name: binary-log-publish
path: ./msbuild.binlog

# Dump logs of the container if something failed
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1

# Publish the NuGet package to NuGet.org when building master branch
publish:
runs-on: ubuntu-18.04
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')
needs: deploy
needs:
- deploy-sqlpackage
- deploy-publish
steps:
# Setup .NET SDK
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.102'
dotnet-version: '3.1.302'

# Download artifacts
- name: download-artifact
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/BuildDacpac/bin/Debug/netcoreapp3.1/BuildDacpac.dll",
"program": "${workspaceFolder}/src/Dacpactool/bin/Debug/netcoreapp3.1/Dacpactool.dll",
"args": [
"-n",
"MyPackage",
Expand All @@ -24,7 +24,7 @@
"-p",
"AnsiNullsOn=true"
],
"cwd": "${workspaceFolder}/src/BuildDacpac",
"cwd": "${workspaceFolder}/src/Dacpactool",
"console": "internalConsole",
"stopAtEntry": false
},
Expand Down
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"markdown",
"latex",
"plaintext"
]
],
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/obj": true
}
}
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/BuildDacpac/BuildDacpac.csproj",
"${workspaceFolder}/src/DacpacTool/DacpacTool.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand All @@ -19,7 +19,7 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/BuildDacpac/BuildDacpac.csproj",
"${workspaceFolder}/src/DacpacTool/DacpacTool.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand All @@ -32,7 +32,7 @@
"args": [
"watch",
"run",
"${workspaceFolder}/src/BuildDacpac/BuildDacpac.csproj",
"${workspaceFolder}/src/DacpacTool/DacpacTool.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.1.91</Version>
<Version>3.2.31</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
60 changes: 30 additions & 30 deletions MSBuild.Sdk.SqlProj.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B0420F9B-A90
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.Sdk.SqlProj", "src\MSBuild.Sdk.SqlProj\MSBuild.Sdk.SqlProj.csproj", "{F4A31183-CB24-4D39-B498-8FE4F1A0CCA2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildDacpac", "src\BuildDacpac\BuildDacpac.csproj", "{94A9E682-EF0D-4B51-8589-30F241CF5837}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D25C8812-D92E-41D5-9BC9-30AFCF45063B}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FD3F6B38-77EB-444F-B9B9-353F26EE8252}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dacpactool", "src\DacpacTool\Dacpactool.csproj", "{78CA944A-928F-48FA-B29F-C5DC96E67684}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A3A4D55B-4484-4501-894F-0B07708A9A1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildDacpac.Tests", "test\BuildDacpac.Tests\BuildDacpac.Tests.csproj", "{E09D484E-594E-4614-8497-47B01D39087D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DacpacTool.Tests", "test\DacpacTool.Tests\DacpacTool.Tests.csproj", "{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -40,38 +40,38 @@ Global
{F4A31183-CB24-4D39-B498-8FE4F1A0CCA2}.Release|x64.Build.0 = Release|Any CPU
{F4A31183-CB24-4D39-B498-8FE4F1A0CCA2}.Release|x86.ActiveCfg = Release|Any CPU
{F4A31183-CB24-4D39-B498-8FE4F1A0CCA2}.Release|x86.Build.0 = Release|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Debug|x64.ActiveCfg = Debug|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Debug|x64.Build.0 = Debug|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Debug|x86.ActiveCfg = Debug|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Debug|x86.Build.0 = Debug|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Release|Any CPU.Build.0 = Release|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Release|x64.ActiveCfg = Release|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Release|x64.Build.0 = Release|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Release|x86.ActiveCfg = Release|Any CPU
{94A9E682-EF0D-4B51-8589-30F241CF5837}.Release|x86.Build.0 = Release|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Debug|x64.ActiveCfg = Debug|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Debug|x64.Build.0 = Debug|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Debug|x86.ActiveCfg = Debug|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Debug|x86.Build.0 = Debug|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Release|Any CPU.Build.0 = Release|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Release|x64.ActiveCfg = Release|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Release|x64.Build.0 = Release|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Release|x86.ActiveCfg = Release|Any CPU
{E09D484E-594E-4614-8497-47B01D39087D}.Release|x86.Build.0 = Release|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Debug|x64.ActiveCfg = Debug|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Debug|x64.Build.0 = Debug|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Debug|x86.ActiveCfg = Debug|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Debug|x86.Build.0 = Debug|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Release|Any CPU.Build.0 = Release|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Release|x64.ActiveCfg = Release|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Release|x64.Build.0 = Release|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Release|x86.ActiveCfg = Release|Any CPU
{78CA944A-928F-48FA-B29F-C5DC96E67684}.Release|x86.Build.0 = Release|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Debug|x64.ActiveCfg = Debug|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Debug|x64.Build.0 = Debug|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Debug|x86.ActiveCfg = Debug|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Debug|x86.Build.0 = Debug|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Release|Any CPU.Build.0 = Release|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Release|x64.ActiveCfg = Release|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Release|x64.Build.0 = Release|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Release|x86.ActiveCfg = Release|Any CPU
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F4A31183-CB24-4D39-B498-8FE4F1A0CCA2} = {B0420F9B-A902-4E9D-8B29-55B4F626483B}
{94A9E682-EF0D-4B51-8589-30F241CF5837} = {B0420F9B-A902-4E9D-8B29-55B4F626483B}
{E09D484E-594E-4614-8497-47B01D39087D} = {FD3F6B38-77EB-444F-B9B9-353F26EE8252}
{78CA944A-928F-48FA-B29F-C5DC96E67684} = {B0420F9B-A902-4E9D-8B29-55B4F626483B}
{2EC1BB4C-C8A1-4C7E-AAE9-24E22EB0A8C4} = {A3A4D55B-4484-4501-894F-0B07708A9A1D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {832DCF12-9633-4AEB-A9D8-444EDF649047}
Expand Down
Loading

0 comments on commit a02bfa8

Please sign in to comment.