Using Microsoft.Build.Evaluation to publish a database project (.sqlproj)

后端 未结 4 2032
耶瑟儿~
耶瑟儿~ 2020-12-09 04:57

I need to be able to publish an SSDT project programmatically. I am looking at using Microsoft.Build to do so but can not find any documentation. It seems pretty simple to c

4条回答
  •  忘掉有多难
    2020-12-09 05:26

    We need a way tell msbuild how and where to publish. Open your project in Visual Studio and begin to Publish it. Enter all needed info in the dialog, including your DB connection info and any custom SQLCMD variable values. Save Profile As... to a file, e.g. Northwind.publish.xml. (You may then Cancel.) Now we can use this and the project file to build and publish:

    // 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});
    

    This can take awhile and may appear to get stuck. Be patient. :)

提交回复
热议问题