diff --git a/src/Tasks/CollectDeclaredReferencesTask.cs b/src/Tasks/CollectDeclaredReferencesTask.cs index 78a4aa2..392d3dc 100644 --- a/src/Tasks/CollectDeclaredReferencesTask.cs +++ b/src/Tasks/CollectDeclaredReferencesTask.cs @@ -266,7 +266,7 @@ private Dictionary GetPackageInfos() List nugetLibraryAssemblies = nugetLibrary.CompileTimeAssemblies .Select(item => item.Path) - .Where(path => !path.EndsWith("_._", StringComparison.Ordinal)) // Ignore special packages + .Where(IsValidFile) .Select(path => { var fullPath = Path.Combine(nugetLibraryAbsolutePath, path); @@ -275,7 +275,9 @@ private Dictionary GetPackageInfos() .ToList(); List buildFiles = nugetLibrary.Build - .Select(item => Path.Combine(nugetLibraryAbsolutePath, item.Path)) + .Select(item => item.Path) + .Where(IsValidFile) + .Select(path => Path.Combine(nugetLibraryAbsolutePath, path)) .ToList(); // Add this package's assets, if there are any @@ -323,6 +325,8 @@ private Dictionary GetPackageInfos() return packageInfos; } + private static bool IsValidFile(string path) => !path.EndsWith("_._", StringComparison.Ordinal); + private HashSet GetTargetFrameworkAssemblyNames() { HashSet targetFrameworkAssemblyNames = new(); diff --git a/src/Tests/E2ETests.cs b/src/Tests/E2ETests.cs index a54e692..4f66a2b 100644 --- a/src/Tests/E2ETests.cs +++ b/src/Tests/E2ETests.cs @@ -507,6 +507,17 @@ public Task WpfApp() expectedWarnings: []); } + [TestMethod] + public Task PackageReferenceWithFakeBuildFile() + { + return RunMSBuildAsync( + projectFile: "Library/Library.csproj", + expectedWarnings: + [ + new Warning("RT0003: PackageReference Microsoft.Extensions.Primitives can be removed", "Library/Library.csproj"), + ]); + } + private static (string ExePath, string Verb) GetMsBuildExeAndVerb() { // On Windows, try to find Visual Studio diff --git a/src/Tests/TestData/PackageReferenceWithFakeBuildFile/Library/Library.cs b/src/Tests/TestData/PackageReferenceWithFakeBuildFile/Library/Library.cs new file mode 100644 index 0000000..f022193 --- /dev/null +++ b/src/Tests/TestData/PackageReferenceWithFakeBuildFile/Library/Library.cs @@ -0,0 +1,7 @@ +namespace Library +{ + public static class Foo + { + public static string Bar() => Newtonsoft.Json.JsonConvert.SerializeObject(null); + } +} diff --git a/src/Tests/TestData/PackageReferenceWithFakeBuildFile/Library/Library.csproj b/src/Tests/TestData/PackageReferenceWithFakeBuildFile/Library/Library.csproj new file mode 100644 index 0000000..48e5973 --- /dev/null +++ b/src/Tests/TestData/PackageReferenceWithFakeBuildFile/Library/Library.csproj @@ -0,0 +1,13 @@ + + + + Library + net472 + + + + + + + +