none
MSBuild behaviour for SSDT Projects

    Question

  • Hi Guys, I'm trying to automate some of the work I do for new projects - I have a folder structure that I would like to use and I was trying to get MsBuild to help set this up for me automatically.

    I am getting an error when using the wildcard include statements in msbuild when trying to change the build properties which says

    "The operation is not allowed because currently this object is not parented."

    My project looks like this:

    <ItemGroup>
        <None Include="Architecture - Docs\**\*" />
        <None Include="Deploy - Hotfixes\**\*" />
        <None Include="Deploy - Project\**\*" />
        <None Include="Deploy - Version\**\*" />
        <None Include="Dev - Items\**\*" />
        <None Include="Dev - Tools\**\*" />
        <None Include="Op - General Helpers\**\*" />
        <None Include="Op - Periodic Helpers\**\*" />
        <None Include="Op - Support Record\**\*" />
        <None Include="Shared - Scripts\**\*" />
      </ItemGroup>
    <ItemGroup>
     <Build Include="Objects - Database Level\**\*" />
     <Build Include="Objects - Schema\**\*" />
    </ItemGroup>

    Is this approach to automatically including/excluding files not supported in SSDT?

    I don't claim to be any expert in MsBuild - is there a better way that would work? Essentially in the set of folder above, some of which should all include build items and the others are just Build=None scripts.

    With just a couple of exceptions, I'd like MsBuild to automatically include any files in subfolders and assign the correct build action.

    I would then like to be able to deal with the exceptions by overriding using the vs solution explorer UI as I need to. (or I will need to make the MsBuild more sophisticated, e.g. setting build=none to any scripts starting with "--" etc.)


    Friday, October 05, 2012 8:54 AM

Answers

  • Hi Alex, you are right it does work but actually it doesn't appear to be useable for my purposes and this may be that MsBuild is not the right tool for the job.

    I want to help automate managing the files in a project and have the build property set automatically depending on the folder\filename. (so schema sql scripts are built, but deploy sql scripts are not)

    You can do something like the below that will add all the files into the correct build group BUT it doesn't handle XSD's for example with metadata - the xsd's all get created with %(FileName) literal in XmlSchemaCollectionName. Worse, when you edit an individual item's metadata, it changes the wildcard item to make all of them the same on the next project load.

    I suspect that this would be a problem with many of the metadata items that SSDT uses

        <None Include="Deploy - Hotfixes\**\*" />
        <None Include="Deploy - Project\**\*" />
        <None Include="Deploy - Version\**\*" />
        <None Include="Dev - Items\**\*" />
        <None Include="Dev - Tools\**\*" />
        <Build Include="Objects - Schema\**\*.xsd">
          <RelationalSchema>dbo</RelationalSchema>
          <XmlSchemaCollectionName>%(FileName)</XmlSchemaCollectionName>
        </Build>
        <Build Include="Objects - Schema\**\*.sql" Exclude="Objects - Schema\**\--*.sql;Objects - Schema\**\*.data.sql" />
        <None Include="Objects - Schema\**\*.data.sql" />
        <None Include="Objects - Schema\**\*.xml" />
        <Build Include="Objects - Database Level\**\*" Exclude="Objects - Database Level\**\--*.sql;Objects - Database Level\**\*.data.sql" />
        <None Include="Objects - Database Level\**\*.data.sql" />
        <None Include="Op - General Helpers\**\*" />
        <None Include="Op - Periodic Helpers\**\*" />
        <None Include="Op - Support Record\**\*" />
        <None Include="Shared - Scripts\**\*" />
    I think I'll stick to using this purely for creating automatic links between 2005 / 2008 projects that share the same sql files and investigate the NUGET / custom add-in / macro approach.

    Thursday, January 03, 2013 3:29 PM

All replies

  • Hi Brett,

    That approach should work.  I created a sample SSDT project and modified the project file to include some folders (both build and non-build) as you describe above.  Opening the project resulted in the correct folder and file artifacts being added.

    Would you be able to share a sample project that is causing the above error?

    Thank you,

    a/c

    Friday, October 12, 2012 9:12 PM
    Moderator
  • Hi Alex, you are right it does work but actually it doesn't appear to be useable for my purposes and this may be that MsBuild is not the right tool for the job.

    I want to help automate managing the files in a project and have the build property set automatically depending on the folder\filename. (so schema sql scripts are built, but deploy sql scripts are not)

    You can do something like the below that will add all the files into the correct build group BUT it doesn't handle XSD's for example with metadata - the xsd's all get created with %(FileName) literal in XmlSchemaCollectionName. Worse, when you edit an individual item's metadata, it changes the wildcard item to make all of them the same on the next project load.

    I suspect that this would be a problem with many of the metadata items that SSDT uses

        <None Include="Deploy - Hotfixes\**\*" />
        <None Include="Deploy - Project\**\*" />
        <None Include="Deploy - Version\**\*" />
        <None Include="Dev - Items\**\*" />
        <None Include="Dev - Tools\**\*" />
        <Build Include="Objects - Schema\**\*.xsd">
          <RelationalSchema>dbo</RelationalSchema>
          <XmlSchemaCollectionName>%(FileName)</XmlSchemaCollectionName>
        </Build>
        <Build Include="Objects - Schema\**\*.sql" Exclude="Objects - Schema\**\--*.sql;Objects - Schema\**\*.data.sql" />
        <None Include="Objects - Schema\**\*.data.sql" />
        <None Include="Objects - Schema\**\*.xml" />
        <Build Include="Objects - Database Level\**\*" Exclude="Objects - Database Level\**\--*.sql;Objects - Database Level\**\*.data.sql" />
        <None Include="Objects - Database Level\**\*.data.sql" />
        <None Include="Op - General Helpers\**\*" />
        <None Include="Op - Periodic Helpers\**\*" />
        <None Include="Op - Support Record\**\*" />
        <None Include="Shared - Scripts\**\*" />
    I think I'll stick to using this purely for creating automatic links between 2005 / 2008 projects that share the same sql files and investigate the NUGET / custom add-in / macro approach.

    Thursday, January 03, 2013 3:29 PM