VisualStudio SQL database project sqlcmdvars TFS d

2019-05-06 15:58发布

I have an SQL database project in VisualStudio 2010 in source control with TFS 2010 with a few branches that each deploy to different servers depending on the configuration profile.

Using a sqlcmdvars file with the configuration profile appended in the filename (Debug.sqlcmdvars, etc..) for each configuration profile lets me specify the unique file path for a particular deployment environment by use of the reserved names Path1 and Path2 for the mdf file and the log file.

<?xml version="1.0" encoding="utf-8"?>
<SqlCommandVariables xmlns="urn:Microsoft.VisualStudio.Data.Schema.Package.SqlCmdVars">
  <Version>1.0</Version>
  <Properties>
    <Property>
      <PropertyName>Path1</PropertyName>
      <PropertyValue>C:\SQLSERVER LOG\$(DatabaseName)\</PropertyValue>
    </Property>
    <Property>
      <PropertyName>Path2</PropertyName>
      <PropertyValue>C:\SQLSERVER DATA\$(DatabaseName)\</PropertyValue>
    </Property>
  </Properties>
</SqlCommandVariables>

Now I'm trying to add a custom FileStream file with an associated FileStream FileGroup

enter image description here

I have added an additional entry in sqlcmdvars files:

<Property>
  <PropertyName>PathBlobStream</PropertyName>
  <PropertyValue>C:\SQLSERVER DATA\$(DatabaseName)\BlobStream\</PropertyValue>
</Property>

But am not sure how to tell the database to use this over what the SchemaObjects\Database Level Objects\Storage\BlobStore.sqlfile.sql has declared:

ALTER DATABASE [$(DatabaseName)]
    ADD FILE (NAME = [BlobStore], FILENAME = 'C:\SQLSERVER DATA\####\BlobStream') TO FILEGROUP [BlobStreamFileGroup];

How do you use the new entry in the sqlcmdvars to override the path for the new FileStream file?

1条回答
贪生不怕死
2楼-- · 2019-05-06 16:36

The best way I found to do this was add additional entries in the dbproj file to use a different schema file depending on the configuration profile:

  <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
    <Build Include="Schema Objects\Database Level Objects\Storage\Files\BlobStore.sqlfile.sql">
      <SubType>Code</SubType>
    </Build>
  </ItemGroup>
  <ItemGroup Condition=" '$(Configuration)' == 'Internal' ">
    <Build Include="Schema Objects\Database Level Objects\Storage\Files\BlobStore.sqlfile.Internal.sql">
      <SubType>Code</SubType>
    </Build>
  </ItemGroup>

The key was copy/pasting the original schema file and appending the configuration profile name in the file name. This keeps the debug variation with the original file name so that any future schema comparisons will be oblivious to the additional variations. You want to include the additional schema files in source control, but if following suite to the entries above, they won't show up in the project. I verified MSBuild handles this correctly. I'm crossing my fingers that TFS will do the same.

查看更多
登录 后发表回答