GitTools / GitVersion

From git log to SemVer in no time
https://gitversion.net/docs/
MIT License
2.8k stars 641 forks source link

[Bug] AzureDevops pipeline: The framework 'Microsoft.NETCore.App', version '2.1.0' was not found. #3014

Closed shatodj closed 2 years ago

shatodj commented 2 years ago

Describe the bug Our pipelines using this task are failing with this message

Starting: GitVersion
==============================================================================
Task         : GitVersion Task
Description  : Easy Semantic Versioning (http://semver.org/) for projects using Git
Version      : 5.0.1
Author       : GitVersion Contributors
Help         : See the [documentation](http://gitversion.readthedocs.org/en/latest/) for help
==============================================================================
/usr/local/bin/dotnet /Users/runner/work/_tasks/GitVersion_e5983830-3f75-11e5-82ed-81492570a08e/5.0.1/core/GitVersion.dll /Users/runner/work/1/s /output buildserver /nofetch /config /Users/runner/work/1/s
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
  - The following frameworks were found:
      3.1.1 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]
      3.1.3 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]
      3.1.6 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]
      3.1.22 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]
      5.0.2 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]
      5.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]
      5.0.8 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]
      5.0.14 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.1.0&arch=x64&rid=osx.11.0-x64
##[error]Error: The process '/usr/local/bin/dotnet' failed with exit code 150
Finishing: GitVersion

Our pipeline is defining the task as following:

         - task: GitVersion@5
            inputs:
              runtime: 'core'
          - bash: |
              echo 'build number: $(build.buildNumber)'
              exit

Expected Behavior

The newer version of .net core should be used.

Actual Behavior

The old version 2.1.0 is used instead.

Possible Fix

Steps to Reproduce

Context

Your Environment

Azure DevOps pipeline task: GitVersion@5.

grendo commented 2 years ago

I am seeing the same. Setting it to use dotnetframework / mono seems to be a workaround.

abosquet commented 2 years ago

From my side set runtime: 'full' saved my day

shatodj commented 2 years ago

So we found 2 ways of fixing that issue:

  1. Adding UseDotNet@2 as the first step in a job like this
          - task: UseDotNet@2
            inputs:
              packageType: 'sdk'
              version: '2.1.x'
  2. Replace GitVersion task with 2 separated tasks gitversion/setup@0 and gitversion/execute@0
          - task: gitversion/setup@0
            inputs:
              versionSpec: '5.x'
          - task: gitversion/execute@0
johnverbiest commented 2 years ago

Same here, currently adding the:

      - task: UseDotNet@2
            inputs:
              packageType: 'sdk'
              version: '2.1.x'

workaround, but a migration to newer dotnet versions would be preferable

arturcic commented 2 years ago

@shatodj https://marketplace.visualstudio.com/items?itemName=gittools.gitversion was deprecated in favor of https://marketplace.visualstudio.com/items?itemName=gittools.gittools. Please you the GitTools bundle that contains GitVersion and not GitVersion

mc0re commented 2 years ago

@arturcic Moving to GitTools didn't fix the problem. I still get this dependency on 2.1.0, and even installing dotnet SDK 2.1.300 does not help.

arturcic commented 2 years ago

@mc0re can you post here the portion of the yaml that installs and then runs the GitVersion from the GitTools bundle

mc0re commented 2 years ago

I have created this template for the purpose:

parameters:
- name: gitversion_config_path
  displayName: Path to "GitVersion.yml" from the .sln file
  type: string
  default: 'GitVersion.yml'

- name: gitversion_version
  displayName: Version of the tool to use
  type: string
  default: '5.x'

- name: gitversion_dotnet
  displayName: GitVersion requires 2.x and 3.x .NET SDKs installed for its execution
  type: object
  # Needs Microsoft.NETCore.App version exactly 2.1.0, which is in SDK 2.1.300
  default: ['2.1.300', '3.1.419']

steps:
- task: gitversion/setup@0
  displayName: 'Setup GitVersion ${{ parameters.gitversion_version }}'
  inputs:
    versionSpec: ${{ parameters.gitversion_version }}

- ${{ each version in parameters.gitversion_dotnet }}:
  - task: DotNetCoreInstaller@0
    displayName: 'Install .NET Core SDK ${{ version }} for GitVersion'
    inputs:
      version: ${{ version }}

- task: gitversion/execute@0
  displayName: Run GitVersion
  inputs:
    useConfigFile: true
    configFilePath: ${{ parameters.gitversion_config_path }}
    updateAssemblyInfo: true

This is the error I am getting. Note, it's an on-premise Azure DevOps installation, and most agents work, but some don't.

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
  - The following frameworks were found:
      3.1.25 at [[redacted]\_work\_tool\dncs\3.1.419\x64\shared\Microsoft.NETCore.App]
      3.1.26 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      6.0.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.1.0&arch=x64&rid=win10-x64
##[error]SyntaxError: Unexpected end of JSON input
daryltucker commented 1 year ago

I was able to work around this:

  1. Add Use .NET Core task before GitVersion task
  2. Package to install: Runtime
  3. Version: 2.1.0

GitVersion is also set up to use dotnet fullframework.

2.1.0 only show up for Runtime from what I can see:

curl https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/2.1/releases.json -s | jq '.releases[]| .runtime.version'

Thankfully, only the Runtime seems to be needed :D