Skip to content

C# Change desktop dotnet assembly lookup to fall back to nuget reference assemblies #15600

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

Merged
merged 10 commits into from
Feb 21, 2024

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 .net core/framework assembly folders.

Commit-by-commit review is suggested.

@github-actions github-actions bot added the C# label Feb 13, 2024
@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
michaelnebel
michaelnebel previously approved these changes Feb 14, 2024
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 !

@tamasvajk tamasvajk force-pushed the buildless/no-mono-dlls branch from 81e1435 to d358f8e Compare February 16, 2024 10:16
Comment on lines +195 to +198
catch (Exception e)
{
logger.LogError($"Error while searching for DLLs in '{path}': {e.Message}");
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
Comment on lines +166 to +168
RemoveFrameworkNugetPackages(dllPaths);
RemoveNugetPackageReference(FrameworkPackageNames.AspNetCoreFramework, dllPaths);
RemoveNugetPackageReference(FrameworkPackageNames.WindowsDesktopFramework, dllPaths);
Copy link
Contributor Author

@tamasvajk tamasvajk Feb 16, 2024

Choose a reason for hiding this comment

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

I think this doesn't work on some early .net core variants, where the framework was split up into many nuget packages, and therefore they wouldn't be identified as framework references but as standard nuget packages. But for the moment, I think it's good enough.

Comment on lines +394 to +397
if (TryRestorePackageManually(FrameworkPackageNames.LatestNetFrameworkReferenceAssemblies, null))
{
runtimeLocation = GetPackageDirectory(FrameworkPackageNames.LatestNetFrameworkReferenceAssemblies, missingPackageDirectory);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Early commits in this PR tested this behaviour, but that's not the case any longer. Is there an easy way of covering this with an integration test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the problem that this is an extremely unhappy path that is hard to replicate (as there none of the runners that satisfy the criteria for missing paths)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's correct. We'd get here if there was no mono installation on linux/macos runners, and no .net install on windows. (I've faced the original issue on a mac with no mono.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, yes, then we have reached the limit for what is integration testable unless we introduce some way of adding extra test configuration (we probably shouldn't do this).
Maybe accept that we can't integration test this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When #15650 and this PR are merged, I'll set up some manual testing to see if the extractor is really working without mono.

| /legacypackages/Newtonsoft.Json.6.0.4/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll |
| /missingpackages/microsoft.netframework.referenceassemblies.net481/1.0.3/build/.NETFramework/v4.8.1/Accessibility.dll |
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do these go into the root and not the DB scratch dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should probably prepend [...] to the paths. I'll do it in a followup PR, because it applies to some other integration tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm making this change in #15678.

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.

Good work! 👍

@tamasvajk tamasvajk merged commit 70a2d16 into github:main Feb 21, 2024
@Jihinokokoro28177
Copy link

じひのこころ28177です。いろいろと有難うございました。

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.

4 participants