Skip to content

Commit

Permalink
Merge pull request #1226 from nunit/issue-1223
Browse files Browse the repository at this point in the history
Don't throw when an unknown / unsupported runtime is installed
  • Loading branch information
CharliePoole authored Sep 25, 2022
2 parents 0409a61 + b7f5ca4 commit d59982b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace NUnit.Engine.Internal.RuntimeFrameworks
{
internal static class NetCoreFrameworkLocator
{
static Logger log = InternalTrace.GetLogger(typeof(NetCoreFrameworkLocator));

public static IEnumerable<RuntimeFramework> FindDotNetCoreFrameworks()
{
List<Version> alreadyFound = new List<Version>();
Expand All @@ -22,7 +24,12 @@ public static IEnumerable<RuntimeFramework> FindDotNetCoreFrameworks()
if (TryGetVersionFromString(dirName, out newVersion) && !alreadyFound.Contains(newVersion))
{
alreadyFound.Add(newVersion);
yield return new RuntimeFramework(RuntimeType.NetCore, newVersion);
// HACK: Avoid Exception for an unknown version - see issue #1223
// Requires change in RuntimeFramework.GetClrVersionForFramework()
if (newVersion.Major <= 7)
yield return new RuntimeFramework(RuntimeType.NetCore, newVersion);
else
log.Error($"Found .NET {newVersion.ToString(2)}, which is not yet supported.");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/NUnitEngine/nunit.engine.core/RuntimeFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public RuntimeFramework(RuntimeType runtime, Version version, string profile)
// Version 0.0 means any version so we can't deduce anything
if (version != DefaultVersion)
{
Debug.Assert(IsFrameworkVersion(version));
if (IsFrameworkVersion(version))
ClrVersion = GetClrVersionForFramework(version);
else
Expand Down
21 changes: 0 additions & 21 deletions src/NUnitEngine/nunit.engine/Services/RuntimeFrameworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,6 @@ private RuntimeFramework SelectRuntimeFrameworkInner(TestPackage package)
return targetFramework;
}


/// <summary>
/// Returns the best available framework that matches a target framework.
/// If the target framework has a build number specified, then an exact
/// match is needed. Otherwise, the matching framework with the highest
/// build number is used.
/// </summary>
public RuntimeFramework GetBestAvailableFramework(RuntimeFramework target)
{
RuntimeFramework result = target;

foreach (RuntimeFramework framework in _availableRuntimes)
if (framework.Supports(target))
{
if (framework.ClrVersion.Build > result.ClrVersion.Build)
result = framework;
}

return result;
}

/// <summary>
/// Use Mono.Cecil to get information about all assemblies and
/// apply it to the package using special internal keywords.
Expand Down

0 comments on commit d59982b

Please sign in to comment.