I have an SSDT database project. I've set up a publish profile that publishes it to an SQL Server 2012 localdb instance. I have found some code that can be used to publish the database programmatically:
First import these:
using Microsoft.Build.Evaluation;
using Microsoft.Build.Logging;
using Microsoft.Build.Framework;
Then publish the DB:
// Create a logger.
FileLogger logger = new FileLogger();
logger.Parameters = @"logfile=Northwind.msbuild.log";
// Set up properties.
var projects = ProjectCollection.GlobalProjectCollection;
projects.SetGlobalProperty("Configuration", "Debug");
projects.SetGlobalProperty("SqlPublishProfilePath", @"Northwind.publish.xml");
// Load and build project.
var dbProject = ProjectCollection.GlobalProjectCollection.LoadProject(@"Northwind.sqlproj");
dbProject.Build(new[]{"Build", "Publish"}, new[]{logger});
When I use Visual Studio 2010 to manually publish the database using the publish profile shown in the code, it takes about 4-10 seconds. However, when I run this code to programmatically do the same thing, it takes about 40 seconds.
I have tried removing the Build target, but this didn't make a noticeable difference.
Why is the performance of the programmatic option poorer? What can I do to achieve the same performance as a manual publish?