BMuuN / vsts-assemblyinfo-task

Assembly Info is an extension for Azure DevOps that populates assembly information metadata from a build pipeline.
https://marketplace.visualstudio.com/items?itemName=bleddynrichards.Assembly-Info-Task
MIT License
44 stars 27 forks source link

Failing to read current <VersionNumber> from .csproj #207

Closed martini1992 closed 1 year ago

martini1992 commented 2 years ago

Using this section: https://github.com/BMuuN/vsts-assemblyinfo-task/wiki/Versioning#keep-parts-of-original-version

Applying an appVersion variable (as in the wiki example) of '#.#.#.$(Build.BuildId)' results in:

Assembly version: 
##[debug]Assembly version: 
Assembly file version: 
##[debug]Assembly file version: 
Informational version: #.#.#.42
##[debug]Informational version: #.#.#.42

The csproj correctly includes <Project> -> <PropertyGroup> with nested <Version> and <AssemblyVersion>, but it seems they aren't being pulled in.

BMuuN commented 2 years ago

Can you post the full output from the task?

martini1992 commented 2 years ago

Sensitive information has been "REDACTED"

##[debug]Evaluating condition for step: 'Set Assembly Metadata'
##[debug]Evaluating: SucceededNode()
##[debug]Evaluating SucceededNode:
##[debug]=> True
##[debug]Result: True
##[section]Starting: Set Assembly Metadata
==============================================================================
Task         : Assembly Info (.Net Core & .Net Standard)
Description  : Set assembly or package information such as Version, Copyright and Repository URL's etc.
Version      : 3.0.755
Author       : Bleddyn Richards
Help         : [More Information](https://marketplace.visualstudio.com/items?itemName=bleddynrichards.Assembly-Info-Task)
==============================================================================
##[debug]agent.TempDirectory=C:\agent\_work\_temp
##[debug]loading inputs and endpoints
##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
##[debug]loading INPUT_DISABLETELEMETRY
##[debug]loading INPUT_FAILONWARNING
##[debug]loading INPUT_FILEENCODING
##[debug]loading INPUT_FILENAMES
##[debug]loading INPUT_FILEVERSIONNUMBER
##[debug]loading INPUT_GENERATEPACKAGEONBUILD
##[debug]loading INPUT_IGNORENETFRAMEWORKPROJECTS
##[debug]loading INPUT_INFORMATIONALVERSION
##[debug]loading INPUT_INSERTATTRIBUTES
##[debug]loading INPUT_LOGLEVEL
##[debug]loading INPUT_PACKAGEREQUIRELICENSEACCEPTANCE
##[debug]loading INPUT_PATH
##[debug]loading INPUT_UPDATEBUILDNUMBER
##[debug]loading INPUT_VERSIONNUMBER
##[debug]loading INPUT_WRITEBOM
##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
##[debug]loaded 19
##[debug]Agent.ProxyUrl=undefined
##[debug]Agent.CAInfo=undefined
##[debug]Agent.ClientCert=undefined
##[debug]Agent.SkipCertValidation=undefined
##[debug]DisableTelemetry=true
##[debug]Path=C:\agent\_work\49\s
##[debug]FileNames=**/*.csproj
##[debug]InsertAttributes=true
##[debug]FileEncoding=utf-8
##[debug]WriteBOM=true
##[debug]GeneratePackageOnBuild=false
##[debug]PackageRequireLicenseAcceptance=false
##[debug]PackageId=undefined
##[debug]PackageVersion=undefined
##[debug]Authors=undefined
##[debug]Company=undefined
##[debug]Product=undefined
##[debug]Description=undefined
##[debug]Copyright=undefined
##[debug]PackageLicenseUrl=undefined
##[debug]PackageLicenseExpression=undefined
##[debug]PackageProjectUrl=undefined
##[debug]PackageIconUrl=undefined
##[debug]RepositoryUrl=undefined
##[debug]RepositoryType=undefined
##[debug]PackageTags=undefined
##[debug]PackageReleaseNotes=undefined
##[debug]Culture=undefined
##[debug]VersionNumber=#.#.#.42
##[debug]FileVersionNumber=#.#.#.42
##[debug]InformationalVersion=#.#.#.42
##[debug]LogLevel=verbose
##[debug]FailOnWarning=false
##[debug]IgnoreNetFrameworkProjects=true
##[debug]UpdateBuildNumber=REDACTED_#.#.#.42
##[debug]AddBuildTag=undefined
Task Parameters...
##[debug]Task Parameters...
Source folder: C:\agent\_work\49\s
##[debug]Source folder: C:\agent\_work\49\s
Source files: **/*.csproj
##[debug]Source files: **/*.csproj
Insert attributes: true
##[debug]Insert attributes: true
File encoding: utf-8
##[debug]File encoding: utf-8
Write unicode BOM: true
##[debug]Write unicode BOM: true
Generate NuGet package on build: false
##[debug]Generate NuGet package on build: false
Require license acceptance: false
##[debug]Require license acceptance: false
Package id: 
##[debug]Package id: 
Package version: 
##[debug]Package version: 
Authors: 
##[debug]Authors: 
Company: 
##[debug]Company: 
Product: 
##[debug]Product: 
Description: 
##[debug]Description: 
Copyright: 
##[debug]Copyright: 
License File: 
##[debug]License File: 
License Expression: 
##[debug]License Expression: 
Project Url: 
##[debug]Project Url: 
Package Icon: 
##[debug]Package Icon: 
Repository Url: 
##[debug]Repository Url: 
Repository type: 
##[debug]Repository type: 
Tags: 
##[debug]Tags: 
Release notes: 
##[debug]Release notes: 
Assembly neutral language: 
##[debug]Assembly neutral language: 
Assembly version: 
##[debug]Assembly version: 
Assembly file version: 
##[debug]Assembly file version: 
Informational version: #.#.#.42
##[debug]Informational version: #.#.#.42
Log Level: verbose
##[debug]Log Level: verbose
Fail on Warning: false
##[debug]Fail on Warning: false
Build Tag: 
##[debug]Build Tag: 
Build Number: REDACTED_#.#.#.42
##[debug]Build Number: REDACTED_#.#.#.42

##[debug]
Setting .Net Core / .Net Standard assembly info...
##[debug]defaultRoot: 'C:\agent\_work\49\s'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]findOptions.skipMissingFiles: 'false'
##[debug]matchOptions.debug: 'false'
##[debug]matchOptions.nobrace: 'true'
##[debug]matchOptions.noglobstar: 'false'
##[debug]matchOptions.dot: 'true'
##[debug]matchOptions.noext: 'false'
##[debug]matchOptions.nocase: 'true'
##[debug]matchOptions.nonull: 'false'
##[debug]matchOptions.matchBase: 'false'
##[debug]matchOptions.nocomment: 'false'
##[debug]matchOptions.nonegate: 'false'
##[debug]matchOptions.flipNegate: 'false'
##[debug]pattern: '**/*.csproj'
##[debug]findPath: 'C:\agent\_work\49\s'
##[debug]statOnly: 'false'
##[debug]findPath: 'C:\agent\_work\49\s'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]findOptions.skipMissingFiles: 'false'
REDACTED
##[debug]321 results
##[debug]found 321 paths
##[debug]applying include pattern
##[debug]adjustedPattern: 'C:\agent\_work\49\s\**/*.csproj'
##[debug]1 matches
##[debug]1 final results
Processing: C:\agent\_work\49\s\REDACTED
Detected file encoding: utf-8
##[debug]Detected file encoding: utf-8
GeneratePackageOnBuild --> false
PackageRequireLicenseAcceptance --> false
InformationalVersion --> #.#.#.42
Verify file encoding: utf-8
##[debug]Verify file encoding: utf-8

##[debug]set AssemblyInfo.Version=
##[debug]Processed: ##vso[task.setvariable variable=AssemblyInfo.Version;isOutput=true;issecret=false;]
##[debug]set AssemblyInfo.FileVersion=
##[debug]Processed: ##vso[task.setvariable variable=AssemblyInfo.FileVersion;isOutput=true;issecret=false;]
##[debug]set AssemblyInfo.InformationalVersion=#.#.#.42
##[debug]Processed: ##vso[task.setvariable variable=AssemblyInfo.InformationalVersion;isOutput=true;issecret=false;]#.#.#.42
##[debug]set AssemblyInfo.PackageVersion=
##[debug]Processed: ##vso[task.setvariable variable=AssemblyInfo.PackageVersion;isOutput=true;issecret=false;]
##[debug]Update build number for build: 42 to: REDACTED_#.#.#.42 at backend.
##[debug]Processed: ##vso[build.updatebuildnumber]REDACTED_#.#.#.42
##[debug]task result: Succeeded
##[debug]Processed: ##vso[task.complete result=Succeeded;]Complete.
##[section]Async Command Start: Update Build Number
Update build number to REDACTED_#.#.#.42 for build 42
##[section]Async Command End: Update Build Number
##[section]Finishing: Set Assembly Metadata
BMuuN commented 2 years ago

Can you confirm if: -

1) You are using Azure DevOps or an on-premise installation 1) The <Version>, <FileVersion> and <InformationalVersion> have values in the *.csproj file

and (if possible) can you give me an example of those values or provide a redacted *.csproj file and I'll do some testing on my end.

martini1992 commented 2 years ago

I have also checked that the file uses Windows line endings (CR LF)

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Version>1.1.2</Version>
    <AssemblyVersion>1.1.2.0</AssemblyVersion>
    <UserSecretsId>00000000-0000-0000-0000-000000000000</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.8" />
    <PackageReference Include="NLog.Config" Version="4.7.4" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
    <PackageReference Include="NWebsec.AspNetCore.Middleware" Version="3.0.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.Text.Json" Version="4.7.2" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Folder\" />
    <Folder Include="Folder2\Folder\" />
    <Folder Include="Folder3\" />
  </ItemGroup>

</Project>
martini1992 commented 2 years ago

Also... Its an Azure DevOps Server on-premise installation.

BMuuN commented 2 years ago

Thanks for the prompt response 👍🏼

You have a <Version> and <AssemblyVersion> specified in your *.csproj :

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Version>1.1.2</Version>
    <AssemblyVersion>1.1.2.0</AssemblyVersion>
    <UserSecretsId>00000000-0000-0000-0000-000000000000</UserSecretsId>
  </PropertyGroup>

Based on the task output it looks like you're only supplying a value for the "Informational version" task parameter:

Assembly version: 
##[debug]Assembly version: 
Assembly file version: 
##[debug]Assembly file version: 
Informational version: #.#.#.42
##[debug]Informational version: #.#.#.42

Can you ensure your version format #.#.#.$(Build.BuildId) is specified for the "Assembly version" and "Package version" task parameters (not the "Informational version"):

image

This will replace the values in your *.csproj resulting the following:

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Version>1.1.2.42</Version>
    <AssemblyVersion>1.1.2.42</AssemblyVersion>
    <UserSecretsId>00000000-0000-0000-0000-000000000000</UserSecretsId>
  </PropertyGroup>

Please do let me know how you get on.

martini1992 commented 2 years ago

I don't think thats the issue, heres the relevent task and variables from the DevOps Pipeline

variables:
  buildConfiguration: 'Release'
  appVersion: '#.#.#.$(Build.BuildId)'

steps:

- task: Assembly-Info-NetCore@3
  displayName: 'Set Assembly Metadata'
  inputs:
    Path: '$(Build.SourcesDirectory)'
    FileNames: '**/*.csproj'
    InsertAttributes: true
    FileEncoding: 'utf-8' # 'auto' | 'ascii' | 'utf-7' | 'utf-8' | 'utf-16le' | 'utf-16be'
    WriteBOM: true
    #GeneratePackageOnBuild: true
    #PackageRequireLicenseAcceptance: false
    #PackageId: 'vsts-assemblyinfo-task'
    #Authors: 'Example'
    #Company: 'Example Ltd'
    #Product: 'Example'
    #Description: 'Example'
    #Copyright: 'Copyright © $(date:YYYY) Example Ltd'
    #PackageLicenseUrl: 'ExampleLicense.txt'
    #PackageLicenseExpression: 'Example'
    #PackageProjectUrl: 'https://example.com'
    #PackageIconUrl: 'example.png'
    #RepositoryUrl: 'https://example.com'
    #RepositoryType: 'Example'
    #PackageTags: 'Build,Release'
    #PackageReleaseNotes: 'Example'
    #Culture: 'en-GB'
    VersionNumber: '$(appVersion)'
    FileVersionNumber: '$(appVersion)'
    InformationalVersion: '$(appVersion)'
    #PackageVersion: '$(appVersion)'
    LogLevel: 'verbose' # 'normal' | 'verbose' | 'off'
    FailOnWarning: false
    DisableTelemetry: true
    IgnoreNetFrameworkProjects: true
    UpdateBuildNumber: '$(Build.DefinitionName)_$(appVersion)'
    #AddBuildTag: 'v$(appVersion)'
BMuuN commented 2 years ago

I'm seeing a different output to the variables you have defined in your *.yaml. Do you know which version of Node is running on your on-premise server ?

martini1992 commented 2 years ago

The build agent is running Node 17.2.0

BMuuN commented 2 years ago

So I've been debugging the task with Node v17.2.0 and these are the results I'm getting:

here's the task output:

Task Parameters...
Source folder: H:\DEV\GIT\vsts-assemblyinfo-task\tests\projects
Source files: **/Directory.Build.props
Insert attributes: true
File encoding: utf-8
Write unicode BOM: true
Generate XML documentation file: false
Generate NuGet package on build: false
Require license acceptance: false
Package id: 
Package version: 
Authors: 
Company: 
Product: 
Description: 
Copyright: 
License File: 
License Expression: 
Project Url: 
Package Icon: 
Repository Url: 
Repository type: 
Tags: 
Release notes: 
Assembly neutral language: 
Assembly version: #.#.#.42
Assembly file version: #.#.#.42
Informational version: #.#.#.42
Log Level: verbose
Fail on Warning: false
Build Tag: 
Build Number: 

Setting .Net Core / .Net Standard assembly info...
Processing: H:\DEV\GIT\vsts-assemblyinfo-task\tests\projects\Directory.Build.props
Detected file encoding: utf-8
GenerateDocumentationFile --> false
GeneratePackageOnBuild --> false
PackageRequireLicenseAcceptance --> false
AssemblyVersion --> #.#.#.42
FileVersion --> #.#.#.42
InformationalVersion --> #.#.#.42
Verify file encoding: utf-8

and here's the resulting *.csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <GenerateDocumentationFile>false</GenerateDocumentationFile>
    <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
    <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
    <FileVersion>#.#.#.42</FileVersion>
    <InformationalVersion>#.#.#.42</InformationalVersion>
  </PropertyGroup>
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Version>1.1.2</Version>
    <AssemblyVersion>1.1.2.42</AssemblyVersion>
    <UserSecretsId>00000000-0000-0000-0000-000000000000</UserSecretsId>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.8"/>
    <PackageReference Include="NLog.Config" Version="4.7.4"/>
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3"/>
    <PackageReference Include="NWebsec.AspNetCore.Middleware" Version="3.0.0"/>
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2"/>
    <PackageReference Include="System.Text.Json" Version="4.7.2"/>
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Folder\"/>
    <Folder Include="Folder2\Folder\"/>
    <Folder Include="Folder3\"/>
  </ItemGroup>
</Project>

Everything is working as expected from my end. I know this doesn't help you but I thought I'd update you on my findings and let you know I'm continuing to look into the issue for you.

martini1992 commented 2 years ago

Have just checked this morning and can confirm that everything I have posted came from the same build run/commit. Maybe you could try adding some debug messages for when existing values have or have not been found in the csproj file? Or failures to parse the file?

BMuuN commented 2 years ago

@martini1992 are you still facing this issue with the latest version of the task v3.2.1 ?

martini1992 commented 2 years ago

Haven't looked into this for a while, I'll be able to check it out in a week or so.

natelowry commented 2 years ago

~I'm seeing a similar issue on v3.2.1, but might be mis-reading the docs. It kinda looks like it reads the first csproj's version for the # things, then uses that for the rest of the projects. Is that intended behavior?~

~Given the input #.#.1234.5678 if our first project A has [AssemblyVersion("1.0.*")] and is the first processed, it uses 1.0.1234.5678...even if project B has [AssemblyVersion("1.20.*")]. I'd expect project B to have 1.20.1234.5678. I'm probably missing something with that...or maybe it's a separate issue?~

Disregard, I think I was doing something wrong. All good now. Thanks!

BMuuN commented 2 years ago

~I'm seeing a similar issue on v3.2.1, but might be mis-reading the docs. It kinda looks like it reads the first csproj's version for the # things, then uses that for the rest of the projects. Is that intended behavior?~

~Given the input #.#.1234.5678 if our first project A has [AssemblyVersion("1.0.*")] and is the first processed, it uses 1.0.1234.5678...even if project B has [AssemblyVersion("1.20.*")]. I'd expect project B to have 1.20.1234.5678. I'm probably missing something with that...or maybe it's a separate issue?~

Disregard, I think I was doing something wrong. All good now. Thanks!

No worries @natelowry and thanks for the coffee, much appreciated 👍

BMuuN commented 1 year ago

Closing as thread has gone stale. Please re-open if you are still facing the issue.