0

Question

How can I read the version from the AssemblyInfo.cs file and set it as %build.number% in TeamCity?

More Info

Basically I want to read the version (2.2.0) in this example:

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("97f3f431-69a7-48c2-8bf8-7ae29075b72e")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0")]
[assembly: AssemblyFileVersion("2.2.0")]
[assembly: NeutralResourcesLanguage("en-US")]

and use it as my %build.number% in the TeamCity project

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
  • 3
    It wasn't me, but my guess would be a lack of evidence of any research. I stuck the question into google and got loads of hits - why don't any of those work for you? – Charles Mager May 24 '16 at 19:25
  • 1
    @CharlesMager most of the resources online, shows how to replace the AssemblyInfo version. I need to read this version and set it as the pre-defined %build.number% variable in teamcity. – A-Sharabiani May 24 '16 at 19:36
  • @CharlesMager thanks that answered my question. – A-Sharabiani May 24 '16 at 21:29

2 Answers2

1

Why do you want to do that? Generally the requirement is the other way around, i.e. to be able to set %build.number% to AssemblyVersion of AssemblyInfo.cs. And this can be done using AssemblyInfo Patcher

Mohammad Nadeem
  • 9,134
  • 14
  • 56
  • 82
  • Also [File content replacer|https://confluence.jetbrains.com/display/TCD9/File+Content+Replacer] feature can be used. This feature is available since TeamCity 9.1 and it's an extended version of AssemblyInfo Patcher. – Alina Mishina May 31 '16 at 13:49
-1

Build number should always match the assembly version period This way you now which build you deployed in production.