msbuildtasks
msbuildtasks copied to clipboard
Version task with Team Foundation Server
I'm trying to use the Version task to increment the build number on every build. It works beautifully when building locally, but fails in TFS because it can't write back to the version file ("number.txt"). Is there a way to get around this, or do I need to find a different solution? I am new to MSBuild and TFS so I may be missing something obvious. Thanks.
Can you provide a stripped down sample MSBuild script that reproduces the issue?
This is my custom target that causes the error:
<Message Text="Guid: $(NewGuid)" />
<Version VersionFile="number.txt" BuildType="Increment" RevisionType="BuildIncrement">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build)"/>
<PropertyGroup>
<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>
<ProductId>$(NewGuid)</ProductId>
<MsiName>$(ProjectName)-$(ProductVersion)</MsiName>
</PropertyGroup>
<Message Text="MsiName: $(MsiName)"/>
The rest of the script is really just The BTDF 5.0 template proj file with minor edits (this is for a BizTalk application):
<IncludeVirtualDirectories>true</IncludeVirtualDirectories>
<SkipIISReset>false</SkipIISReset>
<UsingMasterBindings>True</UsingMasterBindings>
<RequireXmlPreprocessDirectives>False</RequireXmlPreprocessDirectives>
<PropertyGroup>
<!-- Properties related to building an MSI for server deployments -->
<!-- BizTalk App Version Upgrade -->
<!-- For each new product release to be deployed to your BizTalk servers: -->
<!-- 1) Increment ProductVersion -->
<!-- 2) Generate a new GUID and update ProductId with the new GUID -->
<!-- This allows the new MSI to automatically uninstall (not undeploy!) the old MSI and install the new one. -->
<ProductVersion>1.0.0</ProductVersion>
<ProductId>4c8dca95-3d82-4d2c-84c0-93ce59795e39</ProductId>
<!--<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>-->
<!--<ProductId>$(NewGuid)</ProductId>-->
<!-- BizTalk App Version Upgrade -->
<ProductName>GetAgent for BizTalk</ProductName>
<Manufacturer>Deployment Framework User</Manufacturer>
<PackageDescription>GetAgent</PackageDescription>
<PackageComments>GetAgent</PackageComments>
<!-- NEVER change the ProductUpgradeCode. -->
<ProductUpgradeCode>8977834d-ceb9-4f00-8771-b9897e217601</ProductUpgradeCode>
<Message Text="Guid: $(NewGuid)" />
<Version VersionFile="number.txt" BuildType="Increment" RevisionType="BuildIncrement">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build)"/>
<PropertyGroup>
<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>
<ProductId>$(NewGuid)</ProductId>
<MsiName>$(ProjectName)-$(ProductVersion)</MsiName>
</PropertyGroup>
<Message Text="MsiName: $(MsiName)"/>
Let me try that again. Custom target:
"<Target Name="AutoVersion" AfterTargets="Redist"> <Script Language="C#" Code="$(GuidGenFunction)"> <Output TaskParameter="ReturnValue" PropertyName="NewGuid" /> </Script>
<Message Text="Guid: $(NewGuid)" />
<Version VersionFile="number.txt" BuildType="Increment" RevisionType="BuildIncrement">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build)"/>
<PropertyGroup>
<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>
<ProductId>$(NewGuid)</ProductId>
<MsiName>$(ProjectName)-$(ProductVersion)</MsiName>
</PropertyGroup>
<Message Text="MsiName: $(MsiName)"/>
</Target>"
Whole file:
"
<IncludeVirtualDirectories>true</IncludeVirtualDirectories>
<SkipIISReset>false</SkipIISReset>
<UsingMasterBindings>True</UsingMasterBindings>
<RequireXmlPreprocessDirectives>False</RequireXmlPreprocessDirectives>
<PropertyGroup>
<!-- Properties related to building an MSI for server deployments -->
<!-- BizTalk App Version Upgrade -->
<!-- For each new product release to be deployed to your BizTalk servers: -->
<!-- 1) Increment ProductVersion -->
<!-- 2) Generate a new GUID and update ProductId with the new GUID -->
<!-- This allows the new MSI to automatically uninstall (not undeploy!) the old MSI and install the new one. -->
<ProductVersion>1.0.0</ProductVersion>
<ProductId>4c8dca95-3d82-4d2c-84c0-93ce59795e39</ProductId>
<!--<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>-->
<!--<ProductId>$(NewGuid)</ProductId>-->
<!-- BizTalk App Version Upgrade -->
<ProductName>GetAgent for BizTalk</ProductName>
<Manufacturer>Deployment Framework User</Manufacturer>
<PackageDescription>GetAgent</PackageDescription>
<PackageComments>GetAgent</PackageComments>
<!-- NEVER change the ProductUpgradeCode. -->
<ProductUpgradeCode>8977834d-ceb9-4f00-8771-b9897e217601</ProductUpgradeCode>
<Message Text="Guid: $(NewGuid)" />
<Version VersionFile="number.txt" BuildType="Increment" RevisionType="BuildIncrement">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build)"/>
<PropertyGroup>
<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>
<ProductId>$(NewGuid)</ProductId>
<MsiName>$(ProjectName)-$(ProductVersion)</MsiName>
</PropertyGroup>
<Message Text="MsiName: $(MsiName)"/>
</Project>"
$(Major).$(Minor).$(Build) $(NewGuid) $(ProjectName)-$(ProductVersion)
I will gladly provide the script if you can explain how make display reasonably in this thread. Thanks.
Maybe I can attach it?
Use GitHub Flavored Mark down when pasting code examples use 3 ` to start it followed by the language name (in this case XML) and then close with 3 more of the same character note that it is a backtick and not a single quote (the one directly above TAB next to the 1 key on most US Keyboards):
```xml Code in here ```
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Target Name="Build">
<Message Text="Hello MSBuild!"/>
</Target>
</Project>
You can also use the Preview function on GitHub to ensure proper formatting.
I tried using the Preview, but nothing happened. Trying again.
The offending custom task:
<Target Name="AutoVersion" AfterTargets="Redist">
<Script Language="C#" Code="$(GuidGenFunction)">
<Output TaskParameter="ReturnValue" PropertyName="NewGuid" />
</Script>
<Message Text="Guid: $(NewGuid)" />
<Version VersionFile="number.txt" BuildType="Increment" RevisionType="BuildIncrement">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build)"/>
<PropertyGroup>
<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>
<ProductId>$(NewGuid)</ProductId>
<MsiName>$(ProjectName)-$(ProductVersion)</MsiName>
</PropertyGroup>
<Message Text="MsiName: $(MsiName)"/>
</Target>
Much better! And the full script:
<?xml version="1.0" encoding="utf-8"?>
<!--
Deployment Framework for BizTalk 5.0
Copyright (C) 2004-2012 Thomas F. Abraham and Scott Colestock
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Installer" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">x86</Platform>
<SchemaVersion>1.0</SchemaVersion>
<ProjectName>GetAgent</ProjectName>
<ProjectVersion>1.0</ProjectVersion>
<IncludeOrchestrations>False</IncludeOrchestrations>
<IncludeTransforms>False</IncludeTransforms>
<IncludeSSO>True</IncludeSSO>
<IncludeVirtualDirectories>true</IncludeVirtualDirectories>
<SkipIISReset>false</SkipIISReset>
<UsingMasterBindings>True</UsingMasterBindings>
<RequireXmlPreprocessDirectives>False</RequireXmlPreprocessDirectives>
</PropertyGroup>
<PropertyGroup>
<GuidGenFunction>
<![CDATA[
public static string ScriptMain() {
return System.Guid.NewGuid().ToString().ToUpper();
}
]]>
</GuidGenFunction>
</PropertyGroup>
<PropertyGroup>
<!-- Properties related to building an MSI for server deployments -->
<!-- BizTalk App Version Upgrade -->
<!-- For each new product release to be deployed to your BizTalk servers: -->
<!-- 1) Increment ProductVersion -->
<!-- 2) Generate a new GUID and update ProductId with the new GUID -->
<!-- This allows the new MSI to automatically uninstall (not undeploy!) the old MSI and install the new one. -->
<ProductVersion>1.0.0</ProductVersion>
<ProductId>4c8dca95-3d82-4d2c-84c0-93ce59795e39</ProductId>
<!--<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>-->
<!--<ProductId>$(NewGuid)</ProductId>-->
<!-- BizTalk App Version Upgrade -->
<ProductName>GetAgent for BizTalk</ProductName>
<Manufacturer>Deployment Framework User</Manufacturer>
<PackageDescription>GetAgent</PackageDescription>
<PackageComments>GetAgent</PackageComments>
<!-- NEVER change the ProductUpgradeCode. -->
<ProductUpgradeCode>8977834d-ceb9-4f00-8771-b9897e217601</ProductUpgradeCode>
</PropertyGroup>
<!-- Under TFS Team Build, set CustomizableOutDir property to true in TFS 2005/2008/2010 UpgradeTemplate. -->
<!-- With a workflow build, copy the default template then modify the MSBuild task for the solution build. Set OutDir to blank and -->
<!-- CommandLineArguments to String.Format("/p:SkipInvalidConfigurations=true;TeamBuildOutDir=""{0}"" {1}", BinariesDirectory, MSBuildArguments). -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DeploymentFrameworkTargetsPath>$(MSBuildExtensionsPath)\DeploymentFrameworkForBizTalk\5.0\</DeploymentFrameworkTargetsPath>
<OutputPath Condition="'$(TeamBuildOutDir)' == ''">bin\Debug\</OutputPath>
<OutputPath Condition="'$(TeamBuildOutDir)' != ''">$(TeamBuildOutDir)</OutputPath>
<DeployPDBsToGac>false</DeployPDBsToGac>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DeploymentFrameworkTargetsPath>$(MSBuildExtensionsPath)\DeploymentFrameworkForBizTalk\5.0\</DeploymentFrameworkTargetsPath>
<OutputPath Condition="'$(TeamBuildOutDir)' == ''">bin\Release\</OutputPath>
<OutputPath Condition="'$(TeamBuildOutDir)' != ''">$(TeamBuildOutDir)</OutputPath>
<DeployPDBsToGac>false</DeployPDBsToGac>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Server'">
<DeploymentFrameworkTargetsPath>Framework\</DeploymentFrameworkTargetsPath>
<!-- Get our PDBs into the GAC so we get file/line number information in stack traces. -->
<DeployPDBsToGac>true</DeployPDBsToGac>
</PropertyGroup>
<ItemGroup>
<VDirList Include="*">
<Vdir>GetAgent</Vdir>
<AppPool>GetAgentAppPool</AppPool>
<AppPoolNetVersion>v4.0</AppPoolNetVersion>
<Physdir>..\ServiceFolders\GetAgent</Physdir>
</VDirList>
</ItemGroup>
<ItemGroup>
<VDirList Include="*">
<Vdir>GetAgentHierarchy</Vdir>
<AppPool>GetAgentAppPool</AppPool>
<AppPoolNetVersion>v4.0</AppPoolNetVersion>
<Physdir>..\ServiceFolders\GetAgentHierarchy</Physdir>
</VDirList>
</ItemGroup>
<ItemGroup>
<PropsFromEnvSettings Include="SsoAppUserGroup;SsoAppAdminGroup;VDIR_UserName;VDIR_UserPass" />
</ItemGroup>
<ItemGroup>
<BizTalkHosts Include="BizTalkReceiveHost;BizTalkSendHost;BizTalkReceiveHostRT;BizTalkSendHostRT"/>
</ItemGroup>
<!-- !!! TODO !!! -->
<!-- Add ItemGroup elements that contain one or more Schemas, Orchestrations, Transforms, etc. elements that describe -->
<!-- the specific artifacts in your solution that need to be deployed. Use IntelliSense as a guide. -->
<ItemGroup>
<Schemas Include="fbfs.ES.GetAgent.dll">
<LocationPath>..\$(ProjectName)\bin\$(Configuration)</LocationPath>
</Schemas>
</ItemGroup>
<!-- !!! TODO !!! -->
<Import Project="$(DeploymentFrameworkTargetsPath)BizTalkDeploymentFramework.targets" />
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<!--
The Deployment Framework automatically packages most files into the server install MSI.
However, if there are special folders that you need to include in the MSI, you can
copy them to the folder $(RedistDir) in the CustomRedist target.
To include individual files, add an ItemGroup with AdditionalFiles elements.
-->
<Target Name="AutoVersion" AfterTargets="Redist">
<Script Language="C#" Code="$(GuidGenFunction)">
<Output TaskParameter="ReturnValue" PropertyName="NewGuid" />
</Script>
<Message Text="Guid: $(NewGuid)" />
<Version VersionFile="number.txt" BuildType="Increment" RevisionType="BuildIncrement">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build)"/>
<PropertyGroup>
<ProductVersion>$(Major).$(Minor).$(Build)</ProductVersion>
<ProductId>$(NewGuid)</ProductId>
<MsiName>$(ProjectName)-$(ProductVersion)</MsiName>
</PropertyGroup>
<Message Text="MsiName: $(MsiName)"/>
</Target>
</Project>
Thanks for the tip. Again, it works fine building in Visual Studio, but errors in TFS because it is in source control. I assume I need to do some kind of checkin/checkout, but I can't figure out how.
Hi KGW,
Did you solve this problem? I see one more issue, the Installer-{ProjectName}.cmd file name is different than the msi. CMD file takes the ProductVersion from the default and not from the newly generated one.
Please suggest.