override fun resolve()

in plugin-dotnet-agent/src/main/kotlin/jetbrains/buildServer/script/ToolVersionResolverImpl.kt [17:50]


    override fun resolve(toolPath: File): CsiTool {
        var supportedRuntimes = getSupportedRuntimes(toolPath).toList()

        var tool: CsiTool?
        if (!_virtualContext.isVirtual) {
            var agentRuntimes = _runtimesProvider.getRuntimes().map { Version(it.version.major, it.version.minor) }.distinct().toList()

            // try to find major match first
            tool = supportedRuntimes.filter {
                val runtimeVersion = it.runtimeVersion
                val runtimeRange = runtimeVersion.including() to Version(runtimeVersion.major + 1).excluding()
                val anyAgentRuntimeMatches = agentRuntimes.any { runtimeRange.contains(it) }
                LOG.debug("[Major matching] version: $runtimeVersion, range: ${runtimeRange}, any agent runtime matches: $anyAgentRuntimeMatches")
                anyAgentRuntimeMatches
            }.maxByOrNull { it.runtimeVersion }

            // fallback to major roll-forward if no matches found
            if (tool == null) {
                tool = supportedRuntimes.filter {
                    val runtimeVersion = it.runtimeVersion
                    val runtimeRange = runtimeVersion.including() to Version(Int.MAX_VALUE).including()
                    val anyAgentRuntimeMatches = agentRuntimes.any { runtimeRange.contains(it) }
                    LOG.debug("[Major roll-forward matching] version: $runtimeVersion, range: ${runtimeRange}, any agent runtime matches: $anyAgentRuntimeMatches")
                    anyAgentRuntimeMatches
                }.maxByOrNull { it.runtimeVersion }
            }
        } else {
            // Should return .NET Runtime LTS version for docker 6.0.0, 8.0.0 etc. according to https://dotnet.microsoft.com/en-us/platform/support/policy
            // or any newest available version
            tool = supportedRuntimes.filter { it.runtimeVersion.major % 2 == 0 }.maxByOrNull { it.runtimeVersion } ?: supportedRuntimes.maxByOrNull { it.runtimeVersion }
        }

        return tool ?: throw RunBuildException("Cannot find a supported version of $RUNNER_DESCRIPTION.")
    }