I'm not sure about the finished tool, but it is quite simple to use the SMO library (Microsoft.SqlServer.Smo, .SmoEnum, .SqlEnum):
using Microsoft.SqlServer.Management.Smo; var server = new Server("localhost"); var database = server.Databases["databaseName"]; var transfer = new Transfer(database); var options = new ScriptingOptions();
I built a simple tool using this method to restore the creation of my script product database as part of the pre-build steps in the settings builder.
source share