X Tutup
The Wayback Machine - https://web.archive.org/web/20240214155509/https://github.com/github/codeql/pull/15600
Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Feb 13, 2024

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.net481 nuget 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.

@github-actions github-actions bot added the C# label Feb 13, 2024

var dir = monoDirs.FirstOrDefault(Directory.Exists);
var monoPathEnv = Environment.GetEnvironmentVariable(EnvironmentVariableNames.MonoPath);
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@tamasvajk tamasvajk marked this pull request as ready for review February 13, 2024 14:26
@tamasvajk tamasvajk requested a review from a team as a code owner February 13, 2024 14:26
@michaelnebel michaelnebel self-requested a review February 14, 2024 09:15
@@ -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",
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good @tamasvajk !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants
X Tutup