mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
C#: Use reference assemblies instead of implementation assemblies.
This commit is contained in:
@@ -10,16 +10,44 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
private readonly Version? preReleaseVersion;
|
||||
private readonly string? preReleaseVersionType;
|
||||
private bool IsPreRelease => preReleaseVersionType is not null && preReleaseVersion is not null;
|
||||
public string FullPath
|
||||
|
||||
private string FullVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
var preRelease = IsPreRelease ? $"-{preReleaseVersionType}.{preReleaseVersion}" : "";
|
||||
var version = this.version + preRelease;
|
||||
return Path.Combine(dir, version);
|
||||
return this.version + preRelease;
|
||||
}
|
||||
}
|
||||
|
||||
public string FullPath => Path.Combine(dir, FullVersion);
|
||||
|
||||
/**
|
||||
* The full path to the reference assemblies for this runtime.
|
||||
* This is the same as FullPath, except that we assume that the
|
||||
* reference assemblies are in a directory called "packs" and
|
||||
* the reference assemblies themselves are in a directory called
|
||||
* "<Framework>.Ref/ref".
|
||||
* Example:
|
||||
* FullPath: /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.2
|
||||
* FullPathReferenceAssemblies: /usr/share/dotnet/packs/Microsoft.NETCore.App.Ref/7.0.2/ref
|
||||
*/
|
||||
public string? FullPathReferenceAssemblies
|
||||
{
|
||||
get
|
||||
{
|
||||
var directories = dir.Split(Path.DirectorySeparatorChar);
|
||||
if (directories.Length >= 2)
|
||||
{
|
||||
directories[^2] = "packs";
|
||||
directories[^1] = $"{directories[^1]}.Ref";
|
||||
return Path.Combine(string.Join(Path.DirectorySeparatorChar, directories), FullVersion, "ref");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DotnetVersion(string dir, string version, string preReleaseVersionType, string preReleaseVersion)
|
||||
{
|
||||
this.dir = dir;
|
||||
|
||||
@@ -94,6 +94,18 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
}
|
||||
}
|
||||
|
||||
private string? GetVersion(string framework)
|
||||
{
|
||||
if (NewestRuntimes.TryGetValue(framework, out var version))
|
||||
{
|
||||
var refAssemblies = version.FullPathReferenceAssemblies;
|
||||
return Directory.Exists(refAssemblies)
|
||||
? refAssemblies
|
||||
: version.FullPath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the .NET runtime location to use for extraction.
|
||||
/// </summary>
|
||||
@@ -105,9 +117,9 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
}
|
||||
|
||||
// Location of the newest .NET Core Runtime.
|
||||
if (NewestRuntimes.TryGetValue(netCoreApp, out var netCoreVersion))
|
||||
if (GetVersion(netCoreApp) is string path)
|
||||
{
|
||||
return netCoreVersion.FullPath;
|
||||
return path;
|
||||
}
|
||||
|
||||
if (DesktopRuntimes.Any())
|
||||
@@ -122,14 +134,6 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
/// <summary>
|
||||
/// Gets the ASP.NET runtime location to use for extraction, if one exists.
|
||||
/// </summary>
|
||||
public string? GetAspRuntime()
|
||||
{
|
||||
// Location of the newest ASP.NET Core Runtime.
|
||||
if (NewestRuntimes.TryGetValue(aspNetCoreApp, out var aspNetCoreVersion))
|
||||
{
|
||||
return aspNetCoreVersion.FullPath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public string? GetAspRuntime() => GetVersion(aspNetCoreApp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user