davefester
davefester

Reputation: 41

TFS2017 dotnet build not overriding Version number

I am working with the TFS2017 build process and am having issues with versioning the assemblies. I am using the dotnet build task, command is set to build, Projects is set to **/*.sln and arguments set to --configuration $(BuildConfiguration) /p:Version=$(Build.BuildNumber)

When looking at the TFS build log the right command is executed (see below)

"C:\Program Files\dotnet\dotnet.exe" build C:\_agent\_work\13\s\*nameofsolution*.sln --configuration Release /p:Version=1100.1.0.0005

However the version of the assembly (File Version and Product Version) show as 1.0.0.

In the csproj file there is no <Version> element.

When I run the above generate command on the build server as the build agent user the assembly is versioned correctly. Is there something that I am missing in my csproj or as part of the solution properties?

Upvotes: 4

Views: 2968

Answers (2)

Andrei Orlov
Andrei Orlov

Reputation: 908

I had the same issue and found out that if .csproj contains <GenerateAssemblyInfo>false</GenerateAssemblyInfo> the version parameter is completely ignored. See the open issue associated with that. Making it true or removing this item should resolve the problem.

Upvotes: 6

EverPresent
EverPresent

Reputation: 1970

TL&DR

Make sure your subsequent build steps on your build server, are passing any necessary --no-build flags to prevent the dotnet command from recompiling by default!!! E.G.:

dotnet test my.csproj --no-build --no-restore
dotnet publish my.csproj --output mydir --no-build --no-restore


OK! I ran into this exact issue when using TeamCity for my build server. I would run through the build process via TeamCity, and my output nuget file would contain DLLs with the default version 1.0.0.0. But when I would look at the build logs, I would take the dotnet build command from the log file, run it on the server, and I would get versioned dlls in the bin directories.

Here's what I found out was happening. In my build pipeline, after the build command, I was also running other commands like dotnet test and dotnet publish. These commands, by default, will recompile the solution/project without the build arguments! In addition they will recompile any referenced dependency projects.

Upvotes: 7

Related Questions