Kick off a data generation plan programmtically
In order to integrate VSTS 2008 Database Edition fully into your development lifecycle, one thing you will probably want to do is kick off a data generation plan automatically during certain activities. Luckily, this is built into some scenarios, like running unit tests--by specifying the "test data" configuration, you can optionally choose to have a database deployment and data generation plan execute prior to the tests starting. Sometimes, however, you just want to run a DG plan, and don't want to have to open the file in VS, click the little button, select the database, and answer the "should I truncate the tables first?" question. One great way to get around this is to use a built-in MSBuild task that was provided to run data generation plans. You can incorporate it into a particular build configuration, or just write yourself a small standalone MSBuild project, along with a bat file to kick it off.
Here's a quick sample, stolen and modified from this post in the MSDN forums:
Filename: RunDataGen.proj
<Project DefaultTargets="DataGen" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--Import the settings-->
<Import Project="C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\TeamData\Microsoft.VisualStudio.TeamSystem.Data.Tasks.targets" />
<Target Name="DataGen">
<Message Text="$(MSBuildBinPath)"/>
<DataGeneratorTask
ConnectionString="$(ConnectionString)"
SourceFile="$(SourceFile)"
PurgeTablesBeforePopulate="$(PurgeTablesBeforePopulate)"
/>
</Target>
</Project>
Filename: RunDataGen.bat
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe RunDataGen.proj /p:ConnectionString="server=(local);database=MyDatabaseName.Deployed;Trusted_Connection=true";SourceFile="C:\Projects\MyProject\MyProject.Database\Data Generation Plans\LoadTablesForUnitTests.dgen";PurgeTablesBeforePopulate=True