简体   繁体   中英

Setting a version in MSBUILD from TFS Build

I have an msbuild script that runs on Team Foundation build. One of the projects in the build is a clickOnce app. So far I have worked out how to get the script to publish the project to the right place but I am unable to set the click once application version.

I set the version using the TFSVersion Task from msbuildcommunitytasks this seems to work ok I can see my version number updated. The problem seems to be that when we enter the CompileConfiguration and publish section this version number is reset back to the initial value. How do I get this value to propagate?

When I get to BeforeCompile the Revision matches my changeset but when I get to BeforeCompileConfiguration the Revision is back to 0.

Here are the script highlights:

<PropertyGroup>
  <CustomizablePublishDir>true</CustomizablePublishDir>
  <SkipLabel>true</SkipLabel>
  <!-- Version Settings -->
  <Major>2</Major>
  <Minor>12</Minor>
  <Build>0</Build>
  <Revision>0</Revision>

  <GetDependsOn>
    $(GetDependsOn);
    Version
  </GetDependsOn>
</PropertyGroup>

<ItemGroup>
  <SolutionToBuild Include="$(BuildProjectFolderPath)/../../AutoBuildTest/AutoBuildTest.sln" />
  <SolutionToPublish Include="@(SolutionToBuild)" >
    <Properties>
      PublishDir=\\DeployServer\Deploy\AutoBuildTest\;
      MinimumRequiredVersion=$(Major).$(Minor).0.0;
      ApplicationVersion=$(Major).$(Minor).$(Build).$(Revision)
    </Properties>
  </SolutionToPublish>
</ItemGroup>

<Target Name="Version">
  <Message Importance="high" Text="Updating Version: $(Major).$(Minor).$(Build).$(Revision)"/>
  <TfsVersion LocalPath="$(SolutionRoot)">
    <Output TaskParameter="Changeset" PropertyName="Revision"/>
  </TfsVersion>
  <Time Format="ddMM">
    <Output TaskParameter="FormattedTime" PropertyName="Build" />
  </Time>
  <Message Importance="high" Text="New Version: $(Major).$(Minor).$(Build).$(Revision)"/>
</Target>

This could be because the SolutionToBuild itemgroup is populated with the value of 0, and therefore the Property receives that value for $(Revision) .

You could try overriding BeforeCompileConfiguration to dynamically include that solution after the version number is updated instead of at the beginning of the script, like so:

<Target Name="BeforeCompileConfiguration">
    <ItemGroup>
        <SolutionToPublish Include="@(SolutionToBuild)" >
            <Properties>
              PublishDir=\\DeployServer\Deploy\AutoBuildTest\;
              MinimumRequiredVersion=$(Major).$(Minor).0.0;
              ApplicationVersion=$(Major).$(Minor).$(Build).$(Revision)
            </Properties>
        </SolutionToPublish>
    </ItemGroup>
</Target>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM