0

I have an azure pipeline set up to build a .net framework class library. The current setup is 1 Solution and 1 Project within the solution and this all works fine. I use the Assembly Info Reader extension to read AssemblyInfo.cs which is used for versioning. This works fine and completely as expected.

What I'm wanting to achieve is to add a second project to the solution and build this using the same pipeline and it's own versioning from the AssemblyInfo.cs file in the second project. This somewhat works in the sense that it build the project fine however it seems that I can't use separate AssemblyInfo.cs files to give each file it's own version. eg

I'm expecting Project1.0.1.0-ci-20230117-153658 & Project2.2.0.0-ci-20230117-153658 But I'm getting Project1.2.0.0-ci-20230117-153658 & Project2.2.0.0-ci-20230117-153658

So they're both taking the same version number rather than separate ones.

The Steps in my pipeline are below.

steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore'

- task: MSBuild@1
  displayName: 'Build solution **/*.sln'

- task: kherzog.AssemblyInfoReader.assembly-info-reader-build-task.AssembyInfoReader@3
  displayName: 'Generate variables **\AssemblyInfo.cs '

- task: NuGetCommand@2
  displayName: 'NuGet pack'
  inputs:
    command: pack
    versioningScheme: byPrereleaseNumber
    majorVersion: '$(AssemblyInfo.AssemblyVersion.Major)'
    minorVersion: '$(AssemblyInfo.AssemblyVersion.Minor)'
    patchVersion: '$(AssemblyInfo.AssemblyVersion.Build)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
Conor
  • 736
  • 1
  • 13
  • 33

1 Answers1

-1

You are packing a single NuGet, so why do you need to extract both versions from assemblies if you are packing a single NuGet?

AssemblyInfoReader has a propety to choose the path where AssemblyInfo.cs is. Try adding serchPattern to your AssemblyInfoReader task, this would let you extract the info from the project you need:

- task: AssembyInfoReader@3
  displayName: 'Get Assembly Info'
  inputs:
    searchPattern: '$(projectFolder)/Properties/AssemblyInfo.cs'

As you want to extract both versions from two different projects, I think you should use different jobs, one for any project, and in each job extract thos properties from the proper assembly.

Vicnroll
  • 64
  • 6
  • I'm not, each project generates a separate package hence the need for 2 separate versions – Conor Jan 19 '23 at 09:08
  • Using different jobs, you probably can achive this, each job is isolated from others unless you don't specify dependencies from the other ones. So each job can build and publish an individual package and you can reference individual AssemblyInfo.cs file in each job. Refs: [stages](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azure-devops&tabs=yaml#specify-stages) – Vicnroll Jan 19 '23 at 09:32