I'm trying to migrate
my app from net 4.6.1
to netcore2.0
and some problems with Microsoft.SqlServer.Dac
have been occurred. I'm deploying the database from a .dacpac
file using DacServices (Microsoft.SqlServer.Dac 1.0.1)
, but this package supports
only net 4.6.1.
How can I deploy .dacpac
file from netcore
application?
Thanks for answers!

- 1,171
- 1
- 10
- 23

- 160
- 1
- 7
3 Answers
The .NET Core
support for DacFx
is planned, but not here yet and you can't do it this way in .NET Core
. Now if add a NuGet
package Microsoft.SqlServer.DacFx.x64
restore will print you:
Package 'Microsoft.SqlServer.DacFx.x64 140.3881.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'
For a while, you can use the command line utility SqlPackage.exe
SqlPackage.exe
/Action:Publish
/SourceFile:C:/file.dacpac
/TargetConnectionString:[Connection string]
And you can run it programmatically:
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = @"C:\Program Files (x86)\Microsoft SQL Server\<Version>\DAC\bin\SqlPackage.exe",
Arguments = "/Action:Publish /SourceFile:C:/file.dacpac /TargetConnectionString:[Connection string]"
};
process.StartInfo = startInfo;
process.Start();

- 30,789
- 8
- 97
- 121
-
1is there still no way to deploy a dacpac (from .NET core) without calling the sqlpackage.exe? – bytedev Oct 22 '18 at 10:41
-
@bytedev as I mentioned in answer keep an eye on https://github.com/Microsoft/DACExtensions/issues/20 – Dmitry Pavlov Oct 23 '18 at 16:34
-
1I only asked cos your original answer is now 2.5 years old ;-) – bytedev Oct 24 '18 at 09:22
-
As we can see at the moment `DacFx .NET Core Support #20` is still `Open` – Dmitry Pavlov Oct 24 '18 at 19:08
-
I have incorporated the answer into my `post-build event command line` so that the database is automatically created. – taylorswiftfan Apr 04 '19 at 23:51
-
2This answer should be updated as the GA package supporting .NET Core is out already. https://www.nuget.org/packages/Microsoft.SqlServer.DACFx – akrobet Jan 27 '20 at 11:05
Good news as of Nov 15, 2018:
... the preview package which supports netcoreapp2.1 and net46: https://www.nuget.org/packages/Microsoft.SqlServer.DACFx/150.4240.1-preview
Be mindful it's the Microsoft.SqlServer.DacFx nuget package not the Microsoft.SqlServer.DacFx.x86 nor Microsoft.SqlServer.DacFx.x64 packages and you need to enable pre-release mode in nuget.
Discussed in the same thread:
https://github.com/Microsoft/DACExtensions/issues/20#issuecomment-439222493
Next up, I need to find out if it works...

- 16,657
- 11
- 74
- 152
Microsoft.SqlServer.DacFx nuget package is now released for netstandard2.0: https://www.nuget.org/packages/Microsoft.SqlServer.DacFx/
To publish a dacpac file to SQL Server LocalDB you can use:
using Microsoft.SqlServer.Dac;
...
var dacpac = DacPackage.Load(@"path\to.dacpac");
var dacpacService = new DacServices("Server=(localdb)\\mssqllocaldb;Database=TargetDatabase;Trusted_Connection=True;MultipleActiveResultSets=true");
dacpacService.Publish(dacpac, "TargetDatabase", new PublishOptions());

- 66
- 4