Skip to content

Commit f8a5772

Browse files
authored
Merge pull request #22889 from michaelnebel/csharp/moredepmanlogging
C#: Add some more logging to the Dependency Manager.
2 parents 61ef133 + 3f2a590 commit f8a5772

5 files changed

Lines changed: 27 additions & 13 deletions

File tree

‎csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private void AddNetFrameworkDlls(ISet<AssemblyLookupLocation> dllLocations, ISet
295295

296296
string? runtimeLocation = null;
297297

298-
if (fileContent.IsNewProjectStructureUsed)
298+
if (fileContent.IsSdkProjectStructureUsed)
299299
{
300300
runtimeLocation = Runtime.NetCoreRuntime;
301301
}

‎csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FileContent.cs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public bool IsAspNetCoreDetected
5454
{
5555
get
5656
{
57-
return IsNewProjectStructureUsed && UseAspNetCoreDlls;
57+
return IsSdkProjectStructureUsed && UseAspNetCoreDlls;
5858
}
5959
}
6060

@@ -102,13 +102,13 @@ public bool IsLegacyProjectStructureUsed
102102
}
103103
}
104104

105-
private bool isNewProjectStructureUsed = false;
106-
public bool IsNewProjectStructureUsed
105+
private bool isSdkProjectStructureUsed = false;
106+
public bool IsSdkProjectStructureUsed
107107
{
108108
get
109109
{
110110
initialize.Run();
111-
return isNewProjectStructureUsed;
111+
return isSdkProjectStructureUsed;
112112
}
113113
}
114114

@@ -228,7 +228,7 @@ private void DoInitialize()
228228

229229
// Determine project structure:
230230
isLegacyProjectStructureUsed = isLegacyProjectStructureUsed || MicrosoftCSharpTargets().IsMatch(line);
231-
isNewProjectStructureUsed = isNewProjectStructureUsed
231+
isSdkProjectStructureUsed = isSdkProjectStructureUsed
232232
|| ProjectSdk().IsMatch(line)
233233
|| FrameworkReference().IsMatch(line);
234234
// TODO: we could also check `<Sdk Name="Microsoft.NET.Sdk" />`
@@ -240,6 +240,14 @@ private void DoInitialize()
240240
logger.LogDebug($"Failed to read file {file}, exception: {ex}");
241241
}
242242
}
243+
244+
logger.LogInfo("Finished reading project files.");
245+
logger.LogInfo($"Legacy project structure usage detected: {isLegacyProjectStructureUsed}");
246+
logger.LogInfo($"SDK project structure usage detected: {isSdkProjectStructureUsed}");
247+
logger.LogInfo($"ASP.NET usage detected: {useAspNetCoreDlls}");
248+
logger.LogInfo($"Windows Forms usage detected: {useWindowsForms}");
249+
logger.LogInfo($"WPF usage detected: {useWpf}");
250+
logger.LogInfo($"Implicit usings enabled: {useImplicitUsings}");
243251
}
244252

245253
[GeneratedRegex("(?<!<!--.*)<PackageReference.*\\sInclude=\"(.*?)\".*/?>", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline)]

‎csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,9 @@ public HashSet<AssemblyLookupLocation> Restore()
148148
.Where(path => IsPathInSubfolder(path, legacyPackageDirectory.DirInfo.FullName, "tools"))
149149
.ToList();
150150

151-
if (nugetPackageDllPaths.Count > 0)
152-
{
153-
logger.LogInfo($"Restored {nugetPackageDllPaths.Count} NuGet DLLs.");
154-
}
151+
152+
logger.LogInfo($"Restored {nugetPackageDllPaths.Count} NuGet DLLs from packages.config files using the NuGet CLI.");
153+
155154
if (excludedPaths.Count > 0)
156155
{
157156
logger.LogInfo($"Excluding {excludedPaths.Count} NuGet DLLs.");
@@ -163,6 +162,13 @@ public HashSet<AssemblyLookupLocation> Restore()
163162
}
164163

165164
nugetPackageDllPaths.ExceptWith(excludedPaths);
165+
166+
logger.LogInfo($"Using {nugetPackageDllPaths.Count} DLLs as dependency candidates from NuGet packages restored via the NuGet CLI based on packages.config files.");
167+
foreach (var path in nugetPackageDllPaths)
168+
{
169+
logger.LogDebug($"Using NuGet DLL as dependency candidate: {path}");
170+
}
171+
166172
assemblyLookupLocations.UnionWith(nugetPackageDllPaths.Select(p => new AssemblyLookupLocation(p)));
167173
}
168174
catch (Exception exc)

‎csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorBase.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override IEnumerable<string> Run()
3939
return [];
4040
}
4141

42-
if (!fileContent.IsNewProjectStructureUsed)
42+
if (!fileContent.IsSdkProjectStructureUsed)
4343
{
4444
logger.LogInfo($"Generating source files from {FileType} files is only supported for new (SDK-style) project files");
4545
return [];

‎csharp/extractor/Semmle.Extraction.Tests/FileContent.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void TestFileContent_LegacyProjectStructure()
179179

180180
// Execute
181181
var isLegacy = fileContent.IsLegacyProjectStructureUsed;
182-
var isNew = fileContent.IsNewProjectStructureUsed;
182+
var isNew = fileContent.IsSdkProjectStructureUsed;
183183

184184
// Verify
185185
Assert.True(isLegacy);
@@ -204,7 +204,7 @@ public void TestFileContent_NewProjectStructure()
204204

205205
// Execute
206206
var isLegacy = fileContent.IsLegacyProjectStructureUsed;
207-
var isNew = fileContent.IsNewProjectStructureUsed;
207+
var isNew = fileContent.IsSdkProjectStructureUsed;
208208

209209
// Verify
210210
Assert.True(isNew);

0 commit comments

Comments
 (0)