This blog is part 3 of Automate Build and Deployment of Azure SQL Database with Continuous Integration and Continuous Deployment.
Content of Tutorial:
Part 1. Prerequisite for Azure SQL Database Build and Deployment Automation
Part 2. Automate Building Azure SQL Database with Continuous Integration
Part 3. Create Nuget package for Azure SQL Database (this page)
Part 4. Orchestrate Azure SQL Database Release with Continuous Deployment
Part 5. Use your own Build and Deployment Agent (coming soon)
Using Visual Studio Team Services you can easily produce a nuget package for your database whenever new build version is created.
In part 3, we will play through
- How to setup your own internal nuget feed for Azure SQL Database.
- How to configure nuget packager and publisher tasks for automation.
- How to nuget install dacpac for your Azure SQL Database.
Let’s start and create your own internal nuget feed. It can be done with one click.
Go to Marketplace >> Browse Marketplace and install Package Management unless you have installed it already.
PACKAGE* section should be added to your web portal. Go to PACKAGE*
Below is a sample screenshot of what you will get after running through this walk through.
First, click + New feed to add a feed definition. Name your feed and Create. It will create a feed in your team project.
It’s really simple like this.
Let’s configure automation tasks to produce and publish nuget package for Azure SQL Database.
Copy Nuget package source URL to clipboard. We will need this URL shortly.
Get the Nuget Credential Provider bundle.
Execute Nuget Package source addition command in command.exe as instructed on the dialog.
This enables your PC to access the nuget feed.
Let’s configure Nuget Packager and Nuget Publisher tasks.
Go to your build definition on Build page on web portal.
Add two tasks. Nuget Packager and Nuget Publisher
First, configure Nuget Packager. Two properties are mandatory.
- Use Build number to version package: Enable
- Package Folder: Browse and Select your database project folder
Next, Configure Nuget Publisher
- Feed type: Internal Nuget Feed
- Internal Feed URL: paste the feed URL from clipboard
Go to the General page of your build definition and replace Build number format to the following
$(date:yyyy.MM.dd)$(rev:.r)
The build number format is important otherwise Nuget packager task will return an execution error.
Save the build definition.
Go to your database project in Visual Studio. Create a new empty file, rename as *.nuspec and add the file to your database project.
Open the nuspec file and insert following. You can change string values as you like. Make sure the <file src> property is correct.
<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <metadata> <id>MyDatabase</id> <version>1.0.0</version> <title>MyDatabase dacpac nuget package</title> <authors>sqldatatools</authors> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>Nuget package demo for MyDatabase</description> <copyright>@your copyright statement</copyright> </metadata> <files> <file src="..\MyDatabase\bin\Debug\MyDatabase.dacpac" target="content\MyDatabase.dacpac" /> </files> </package>
Commit and Sync the change. It will trigger a new build including Nuget packager and publisher tasks.
Go to Team Project web portal and PACKAGE* section. You should be able see your first nuget package is created in the internal feed.
One use for this scenario is to share your database and versions using nuget within your project team. For each package, the feed page shows both Package Manager Console command or Windows Command as shown above. Copy and execute to test.
Copy your nuget install command from your feed page and execute it on command window. It will install Mydatabase.dacpac from the nuget package shown below.
You have completed automation of nuget packaging your database.
Go to Part 4. Orchestrate Azure SQL Database Release with Continuous Deployment and learn how to orchestrate release workflow using the build artifacts you have produced.