0

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?

Community
  • 1
  • 1
Sam
  • 40,644
  • 36
  • 176
  • 219
  • you could try with Process.Start( "msbuild", "/p:Configuration=Debug .... /t:Build;Publish" ); if that's ok for your use case – stijn Aug 29 '13 at 11:52
  • @stijn, that had the same performance as the code in the question. – Sam Aug 29 '13 at 12:15
  • hmm, so it's purely an msbuild vs VisualStudio problem? in that case: turn on detailed or diagnostic logging and try to figure out where the delay occurs? – stijn Aug 29 '13 at 13:01
  • May want to try building the dacpac using MSBuild then publishing using SQLPackage. That may make a difference. – Peter Schott Aug 29 '13 at 21:28
  • @PeterSchott, that had similar performance to the code in the question. – Sam Aug 30 '13 at 10:32

0 Answers0