0

I'm using TFS in Visual Studio 2013 & SSDT to create various SQL Database scripts. i.e. I'm doing all my SQL DB development via VS not SSMS.

Want I'm now trying to achieve is to generate/retreive a version number from an external text file when the project is built/published, based on the functionality posted here:

http://www.codeproject.com/Articles/468855/Working-with-MSBuild-Part-2

So I've added the following to the MyProject.sqlproj xml file:

<PropertyGroup> 
    <WorkingFolder>C:\Source Control\MISTP\Main\DB\SSMS\MyProject</WorkingFolder> 
</PropertyGroup>

<Target Name="GetVersion"> 
    <Message Text="GetVersion: Reading version number from VersionInfo.txt" /> 
    <Attrib Files="$(WorkingFolder)\VersionInfo.txt" Normal="true" /> 
    <Version VersionFile="$(WorkingFolder)\Build\VersionInfo.txt"> 
    <Output TaskParameter="Major" PropertyName="Major" /> 
    <Output TaskParameter="Minor" PropertyName="Minor" /> 
    <Output TaskParameter="Build" PropertyName="Build" /> 
    <Output TaskParameter="Revision" PropertyName="Revision" /> 
    </Version> 
    <Message Text="GetVersion: $(Major).$(Minor).$(Build).$(Revision)" /> 
</Target>

<Target Name="SetVersion" DependsOnTargets="GetVersion"> 
    <Message Text="SetVersionInfo: Updating Versions in all files" /> 
    <CreateItem Include="$(WorkingFolder)\**\*.*"> 
    <Output TaskParameter="Include" ItemName="Files"/> 
    </CreateItem> 
    <Attrib Files="@(Files)" Normal="true" /> 
    <FileUpdate Files="@(Files)" Regex="FileVersionAttribute\(&quot;(\d+)\.(\d+)\.(\d+)\.(\d+)&quot;\)" ReplacementText="FileVersionAttribute(&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;)" /> 
    <FileUpdate Files="@(Files)" Regex="FileVersion\(&quot;(\d+)\.(\d+)\.(\d+)\.(\d+)&quot;\)" ReplacementText=" FileVersion (&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;)" /> 
    <FileUpdate Files="@(Files)" Regex="FileVersion\(&quot;(\d+)\.(\d+)\.(\d+)\.(\d+)&quot;\)" ReplacementText="FileVersion(&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;)" /> 
</Target>

I have a VersionInfo.txt file located in: C:\Source Control\MISTP\Main\DB\SSMS\MyProject\Build

Which simply contains the string: 1.2.3.4

However, this doesn't seem to actually do anything when I Build and/or Publish the project within VS. What am I missing?!

I'm new to MSBuild, but the syntax appears correct - and is largely lifted from the codeproject article - and the path to the file are ok.

It feels like the xml is not being executed, but I'm assuming that it's very presence in the .sqlproj file will result in it being executed.

Thanks

Simon Wray
  • 192
  • 4
  • 12
  • 1
    If I understand your question correctly, you need to update the Dacpac version - see https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e0c93a55-d8bd-4a32-89d9-f46013fc1235/automatic-version-increment-on-datatier-applications?forum=ssdt for information on what's required. – Kevin Cunnane Dec 17 '15 at 20:39

1 Answers1

0

The target isn't triggered during the build. Update "SetVersion" target as following:

<Target Name="SetVersion" DependsOnTargets="GetVersion" AfterTargets="PostBuildEvent"> 
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60