How to get build version in Team Build 2010 Workflow

Is there a way to get the build version number, as we previously did with Msbuild with Team Work 2010 Workflow? Here is a simple example of how we used the version with %(Info.Version) to build.

  <Target Name="CheckFileVersion" DependsOnTargets="AfterDrop"> <ItemGroup> <MyAssemblies Include='$(DropLocation)\$(BuildNumber)\Release\MyApp.exe' /> </ItemGroup> <GetAssemblyIdentity AssemblyFiles="@(MyAssemblies)"> <Output TaskParameter="Assemblies" ItemName="Info"/> </GetAssemblyIdentity> </Target> 

I found several ways to create custom actions with many lines of code, but I think there should be an easier way to do this.

+4
source share
3 answers

GoRoS had the right idea, but it only works correctly for the first time.

To avoid this problem, you need to run this code or similar code in another AppDomain from the build agent, Powershell and InvokeProcessActivity to solve our problem.

GetAssemblyVersionNumber.ps1:

 $error.clear() if ($args.length -ne 1) { Write-Error "Usage: GetAssemblyVersionNumber.ps1 <Assembly>" exit 1 } # Now load the assembly $assembly = [System.Reflection.Assembly]::Loadfile($args[0]) # Get name, version and display the results $name = $assembly.GetName() Write-Host $name.version 

The following is added to the assembly process template.

 InvokeProcessActivity Name: Call Powershell Version Script Filename: "powershell.exe" Arguments: "-NonInteractive -NoProfile -Command " _ + "c:\Builds\GetAssemblyVersionNumber.ps1" _ + " '" + BuildDirectory + "\Binaries\Foobar.dll'" Handle Standard Output (stdOutput) AssignActivity To: VersionInfo Value: stdOutput 
+3
source

You can invoke MSBuild scripts from TFS Build Workflows using the MSBuild Workflow action and continue to do so as always. Or you can create a custom workflow operation to do a similar thing. The best way is likely to depend on what you intend to do with these versions.

You can read about how to start creating user activity here: http://blogs.msdn.com/b/jimlamb/archive/2010/02/12/how-to-create-a-custom-workflow-activity-for -tfs-build-2010.aspx

There are also TFS community build extensions in which there are tons of predefined user actions you can use. One of them is called AssemblyInfo, which sounds promising: http://tfsbuildextensions.codeplex.com/documentation

+1
source

Finally, I found a quick easy way to perform the required operation. Using a simple Assign operation, I wrote the following code:

 To: VersionInfo Value: System.Reflection.Assembly.UnsafeLoadFrom(BuildDetail.DropLocation + _ "\MyApplication.exe").GetName().Version.ToString() 

After that, I can use the VersionInfo variable for whatever I want. I admit that I would prefer to avoid using reflection, but this is an easy and short way that I found that does not use third-party libraries or user actions.

+1
source

All Articles