Gour Gopal
Gour Gopal

Reputation: 581

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.

Upvotes: 6

Views: 3625

Answers (2)

Gour Gopal
Gour Gopal

Reputation: 581

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!)

Upvotes: 11

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32250

According to the TeamCity AssemblyInfo patcher docs:

...after this build feature is configured, it will run before the first build step. TeamCity will first perform replacement in the files found in the build checkout directory and then run your build.

However, the values you have on the Package tab of the DLL projects' settings (your first screenshot) are applied during the build process itself, that is when MSBuild processes your projects. I suspect the values set by TeamCity Assembly patcher are replaced back to defaults here.

Upvotes: 2

Related Questions