Skip to content

Commit 291d7b3

Browse files
committed
C#: Use reference assemblies instead of implementation assemblies.
1 parent a966c0e commit 291d7b3

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotnetVersion.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,44 @@ internal record DotnetVersion : IComparable<DotnetVersion>
1010
private readonly Version? preReleaseVersion;
1111
private readonly string? preReleaseVersionType;
1212
private bool IsPreRelease => preReleaseVersionType is not null && preReleaseVersion is not null;
13-
public string FullPath
13+
14+
private string FullVersion
1415
{
1516
get
1617
{
1718
var preRelease = IsPreRelease ? $"-{preReleaseVersionType}.{preReleaseVersion}" : "";
18-
var version = this.version + preRelease;
19-
return Path.Combine(dir, version);
19+
return this.version + preRelease;
2020
}
2121
}
2222

23+
public string FullPath => Path.Combine(dir, FullVersion);
24+
25+
/**
26+
* The full path to the reference assemblies for this runtime.
27+
* This is the same as FullPath, except that we assume that the
28+
* reference assemblies are in a directory called "packs" and
29+
* the reference assemblies themselves are in a directory called
30+
* "<Framework>.Ref/ref".
31+
* Example:
32+
* FullPath: /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.2
33+
* FullPathReferenceAssemblies: /usr/share/dotnet/packs/Microsoft.NETCore.App.Ref/7.0.2/ref
34+
*/
35+
public string? FullPathReferenceAssemblies
36+
{
37+
get
38+
{
39+
var directories = dir.Split(Path.DirectorySeparatorChar);
40+
if (directories.Length >= 2)
41+
{
42+
directories[^2] = "packs";
43+
directories[^1] = $"{directories[^1]}.Ref";
44+
return Path.Combine(string.Join(Path.DirectorySeparatorChar, directories), FullVersion, "ref");
45+
}
46+
return null;
47+
}
48+
}
49+
50+
2351
public DotnetVersion(string dir, string version, string preReleaseVersionType, string preReleaseVersion)
2452
{
2553
this.dir = dir;

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Runtime.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ private static IEnumerable<string> DesktopRuntimes
9494
}
9595
}
9696

97+
private string? GetVersion(string framework)
98+
{
99+
if (NewestRuntimes.TryGetValue(framework, out var version))
100+
{
101+
var refAssemblies = version.FullPathReferenceAssemblies;
102+
return Directory.Exists(refAssemblies)
103+
? refAssemblies
104+
: version.FullPath;
105+
}
106+
return null;
107+
}
108+
97109
/// <summary>
98110
/// Gets the .NET runtime location to use for extraction.
99111
/// </summary>
@@ -105,9 +117,9 @@ public string GetRuntime(bool useSelfContained)
105117
}
106118

107119
// Location of the newest .NET Core Runtime.
108-
if (NewestRuntimes.TryGetValue(netCoreApp, out var netCoreVersion))
120+
if (GetVersion(netCoreApp) is string path)
109121
{
110-
return netCoreVersion.FullPath;
122+
return path;
111123
}
112124

113125
if (DesktopRuntimes.Any())
@@ -122,14 +134,6 @@ public string GetRuntime(bool useSelfContained)
122134
/// <summary>
123135
/// Gets the ASP.NET runtime location to use for extraction, if one exists.
124136
/// </summary>
125-
public string? GetAspRuntime()
126-
{
127-
// Location of the newest ASP.NET Core Runtime.
128-
if (NewestRuntimes.TryGetValue(aspNetCoreApp, out var aspNetCoreVersion))
129-
{
130-
return aspNetCoreVersion.FullPath;
131-
}
132-
return null;
133-
}
137+
public string? GetAspRuntime() => GetVersion(aspNetCoreApp);
134138
}
135139
}

0 commit comments

Comments
 (0)