Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change File/Product version of DLLs in TeamCity using AssemblyInfo Patcher produced from a .net solution?

There are multiple c# class library (DotNet Core 2.1) projects and User Interface (WPF project) in my solution.

Let say a class library project properties have Assembly version 2019.1.15341.0:

Project 1 has Assembly version 2019.1.15341.0

Also, the same Assembly version is assigned to the user interface (WPF application):

[assembly: AssemblyVersion("2019.1.15341.0")]
[assembly: AssemblyFileVersion("2019.1.15341.0")]

In TeamCity, I have configured AssemblyInfo Patcher:

TeamCity AssemblyInfo Patcher

I build the complete solution using TeamCity and the builds were successful:

Build Successful in TeamCity

Now let's see the property of artifacts produced after Building the complete solution:

1. Project 1 (Class library, DLL properties):

project1.dll

2. UserInterface (WPF project):

USER interface exe

I see that the UserInterface.exe's Version has been changed by TeamCity according to it's build counter and build vcs number, but Why the DLL's version is not changed? Am I missing any steps? or anything else?

Any information I am missing please inform.

The properties of EXEs seems fine as expected. The main concern is on the DLLs: It's property is not getting changed.

like image 462
Gour Gopal Avatar asked Dec 17 '22 22:12

Gour Gopal


1 Answers

As mentioned it is a .Net Core project, so it may not be having an AssemblyInfo.cs where Assembly properties are defined.

So go to Build Features in TeamCity, and add a Build Feature.

  1. Select: File content replacer
  2. (optional) Click on Load Template and search or type for Version under .Net Core

Adding File content replacer as Build Feature

  1. You can use a regular expression of your own like: <Version>\S*<\/Version> or use template regex: (<(Version)\s*>).*(<\/\s*\2\s*>)

Replace with:

I have used Replace With: <Version>%MAJOR%.%MINOR%.%build.counter%.%build.vcs.number%</Version> so that <version> and </version> tags don't get deleted as per my regex. It all depends on your regex what you need to replace.

Similarly, I have added other required parameters: other required parameters

Pros: After building the project I can see the expected results in properties.

Cons: Searches and Replaces the files multiple times and not once (the number of Build features, the same number of time it will be executed, and the same number of time it will be reverted!)

like image 51
Gour Gopal Avatar answered Dec 28 '22 23:12

Gour Gopal