Using SQL tasks with ItemGroups

Feb 2, 2010 at 5:58 AM

Am I right in thinking that I can't use the various SQL tasks with itemgroups? For instance, I've defined an itemgroup which lists the 6 databases which make up my solution, together with metadata such as the connection strings needed to connect to the database; I would like to be able to pass that itemgroup to the MSBuild.ExtensionPack.Sql2005.Database task, so I could run a common set of operations against each database (e.g. check that they exist, and if they do, drop them). Is this possible?

At the moment I'm doing it longhand :-(

Sep 14, 2010 at 2:41 PM

Yes, you can. You'll probably want to add metadata to the Items in the ItemGroup. Here's an example:

    <Exec
        Command="&quot;$(VSPath)&quot; &quot;%(LocalSolutionToBuild.Identity)&quot; /Build &quot;%(LocalSolutionToBuild.MSIConfig)|AnyCPU&quot; /Out &quot;$(BuildDirectory)\Package\MSILog.txt&quot;"
        Condition="%(LocalSolutionToBuild.MSIConfig) != ''">
    </Exec>

The LocalSolutionToBuild is an ItemGroup created from the "SolutionToBuild" ItemGroup using the WorkspaceItemConverterTask in TFS. The %(LocalSolutionToBuild.Identity) refers the "Include" attribute for the Item. %(LocalSolutionToBuild.MSIConfig) referes to metadata. This will loop over all of the solutions in the ItemGroup and, if the metadata item "MSIConfig" is not empty, will call VS to build an MSI (it's an ugly hack but that's how you need to do it).

The ItemGroup looks like the following:

  <ItemGroup>
    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../$(Branch)/Project/Solution1.sln">
      <Targets></Targets>
      <Properties></Properties>
      <MSIConfig>Package</MSIConfig>
    </SolutionToBuild>
    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../$(Branch)/Project/Solution2.sln">
      <Targets></Targets>
      <Properties></Properties>
      <MSIConfig>Package</MSIConfig>
    </SolutionToBuild>
  </ItemGroup>

In your case, you'll define the ItemGroup for your databases and add whatever metadata you need.