Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Tasks/CollectDeclaredReferencesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private Dictionary<string, PackageInfo> GetPackageInfos()

List<string> 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);
Expand All @@ -275,7 +275,9 @@ private Dictionary<string, PackageInfo> GetPackageInfos()
.ToList();

List<string> 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
Expand Down Expand Up @@ -323,6 +325,8 @@ private Dictionary<string, PackageInfo> GetPackageInfos()
return packageInfos;
}

private static bool IsValidFile(string path) => !path.EndsWith("_._", StringComparison.Ordinal);

private HashSet<string> GetTargetFrameworkAssemblyNames()
{
HashSet<string> targetFrameworkAssemblyNames = new();
Expand Down
11 changes: 11 additions & 0 deletions src/Tests/E2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Library
{
public static class Foo
{
public static string Bar() => Newtonsoft.Json.JsonConvert.SerializeObject(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
</ItemGroup>

</Project>
Loading