Josh
Josh

Reputation: 31

Azure Pipelines VisualStudioBuild task ignoring AssemblyInfo.cs

This is being built in an on-prem build agent running version 2.200.2. I've tried using VS 2017-2022 (15.0, 16.0, 17.0).

When I build my code locally, it properly parses the AssemblyInfo.cs files and applies the versioning so that when I check the details in Windows properties, it lists the version set in AssemblyFileVersion (I'm also setting AssemblyVersion and AssemblyInformationalVersion for good measure). For some reason, however, when I run the following tasks, all generated dlls and exes come out with a version of 0.0.0.0 instead of what is listed in the AssemblyInfo.cs. $(RVersion) is defaulted to 1.0.23.0 and I've validated that the AssemblyInfo.cs files are properly being updated. The value currently listed in the AssemblyInfo is 1.0.13.0, so even if it wasn't being set, it's still being ignored. Any help in figuring out why the files are being generated with 0.0.0.0 would be appreciated.

- task: Assembly-Info-NetFramework@3   
  inputs:
    Path: '$(Build.SourcesDirectory)'
    FileNames: |
      **\AssemblyInfo.cs
    InsertAttributes: true
    VersionNumber: '$(RVersion)'
    FileVersionNumber: '$(RVersion)'
    InformationalVersion: '$(RVersion)'
    Configuration: $(buildConfiguration)

- task: VSBuild@1   displayName: 'Build .NET Solution'
  inputs:
    solution: '$(solution)'
    vsVersion: '17.0'
    configuration: 'Release'
    platform: $(buildPlatform)
    msbuildArgs: '/p:SkipInvalidConfigurations=true /p:OutDir=$(Build.BinariesDirectory)'
    clean: true

Upvotes: 0

Views: 963

Answers (1)

I also had troubles using the AssemblyInfo task. Using git version task was mentioned, so I would like to point out that it alone is able to set proper values in the AssemblyInfo files. You just need to set the updateAssemblyInfo: true.

The following works for me:

    - task: gitversion/setup@0      
      displayName: Setup GitVersion
      inputs:
        versionSpec: 5.x
    - task: gitversion/execute@0
      name: gitversion
      displayName: Execute GitVersion
      inputs:
        updateAssemblyInfo: true

But also the other version of the git version task has the updateAssemblyInfo parameter:

    - task: GitVersion@5
      inputs:
        updateAssemblyInfo: true

The git version task log will include then something like:

  INFO [04/28/23 14:21:14:93] Updating assembly info files
  INFO [04/28/23 14:21:14:93] Found 1 files
  INFO [04/28/23 14:21:14:95] Done writing

And for me it sets these attributes accordingly to the gitversion configuration (they are already present in the file - I am not sure if that is required or not):

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]

Upvotes: 0

Related Questions