Skip to content

Commit d3e5f67

Browse files
Merge pull request #25353 from dzsquared/dacfx-unpack
adding dacfx content
2 parents 0303202 + 07731e1 commit d3e5f67

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

docs/relational-databases/data-tier-applications/unpack-a-dac-package.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Options for examining the content of a dacpac include:
2727
- importing the .dacpac to a SQL project in Visual Studio
2828
- decompressing the file to view the XML contents
2929
- deploying the .dacpac to a test instance
30+
- invoking the `Unpack()` method from the Microsoft.SqlServer.DacFx .NET API
3031

3132
## Import the .dacpac to a SQL project in Visual Studio
3233

@@ -83,6 +84,39 @@ Beyond Azure Data Studio and SqlPackage, many other tools can be used to deploy
8384
- Visual Studio: SQL Server Data Tools
8485
- [PowerShell](deploy-a-data-tier-application.md#using-powershell)
8586

87+
## Invoke the `Unpack()` method
88+
89+
The the Microsoft.SqlServer.DacFx .NET API provides a [method to unpack](/dotnet/api/microsoft.sqlserver.dac.dacpackage.unpack) a .dacpac to a folder, which can be used to programmatically unpack a .dacpac to a folder as seen. The example .NET application below takes two arguments, the path to the .dacpac file and the path to the output folder, and the result is the contents of the .dacpac being unpacked to 3 XML files and a single .sql file containing all the database objects.
90+
91+
92+
```csharp
93+
using Microsoft.SqlServer.Dac;
94+
95+
namespace DacUnpack
96+
{
97+
class Program
98+
{
99+
static void Main(string[] args)
100+
{
101+
var dacpacPath = args[0];
102+
var outputPath = args[1];
103+
104+
if (!Directory.Exists(outputPath))
105+
{
106+
Directory.CreateDirectory(outputPath);
107+
}
108+
109+
Console.WriteLine("Unpacking {0} to {1}", dacpacPath, outputPath);
110+
using(DacPackage dacpac = DacPackage.Load(dacpacPath))
111+
{
112+
dacpac.Unpack(outputPath);
113+
}
114+
}
115+
}
116+
}
117+
```
118+
119+
86120

87121
## See Also
88122
- [Data-tier Applications](../../relational-databases/data-tier-applications/data-tier-applications.md)

0 commit comments

Comments
 (0)