New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# Change desktop dotnet assembly lookup to fall back to nuget reference assemblies #15600
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| var dir = monoDirs.FirstOrDefault(Directory.Exists); | ||
| var monoPathEnv = Environment.GetEnvironmentVariable(EnvironmentVariableNames.MonoPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this path be mono specific? We could add instead CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NET_FRAMEWORK_PATH, and then we could also cover the above Windows branch too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is a good idea!
We should we able to "override" the entire logic in DesktopRuntimes by setting the environment variable.
| @@ -434,19 +444,19 @@ private void GenerateSourceFileFromImplicitUsings() | |||
| } | |||
|
|
|||
| // Hardcoded values from https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview#implicit-using-directives | |||
| usings.UnionWith(new[] { "System", "System.Collections.Generic", "System.IO", "System.Linq", "System.Net.Http", "System.Threading", | |||
| "System.Threading.Tasks" }); | |||
| usings.UnionWith([ "System", "System.Collections.Generic", "System.IO", "System.Linq", "System.Net.Http", "System.Threading", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice with all the collection expression re-factoring!
| @@ -0,0 +1,8 @@ | |||
| namespace Semmle.Extraction.CSharp.DependencyFetching | |||
| { | |||
| internal class EnvironmentVariableNames | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a good idea!
Maybe consider to write a small comment above each const, what the purpose of the environment variable is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good @tamasvajk !


This PR changes the fallback .net framework assembly lookup. The dependency fetching logic looks up well-known .NET framework locations on disk, such as the common installation directory on Windows or Mono paths. When no framework assemblies are located we fall back to the executing runtime. This process is now extended to download the
microsoft.netframework.referenceassemblies.net481nuget package if we couldn't find the assemblies on disk. With this change we're implementing the assumption that in case of old-style csproj files, we're better off with these reference assemblies than with the dotnet core ones that we ship with the codeql CLI.An environment variable is also added to allow users specify the path to the mono installation directory. This is also used in the corresponding integration test.
Commit-by-commit review is suggested.