@@ -1094,6 +1094,46 @@ public void SolutionFilter_DoesNotOutputExcludedProject(bool useSlnx)
10941094 projects [ 0 ] [ "path" ] . ToString ( ) . Should ( ) . Be ( PathUtility . GetPathWithForwardSlashes ( projectA . ProjectPath ) ) ;
10951095 }
10961096
1097+ [ PlatformFact ( Platform . Windows ) ]
1098+ public async Task DotnetListPackage_PackageWithTargetsFileErrors_ReturnsCorrectResults ( )
1099+ {
1100+ // Arrange
1101+ using var pathContext = _fixture . CreateSimpleTestPathContext ( ) ;
1102+ _fixture . CreateDotnetNewProject ( pathContext . SolutionRoot , ProjectName , args : "classlib" , _testOutputHelper ) ;
1103+ string projectPath = Path . Combine ( pathContext . SolutionRoot , ProjectName , $ "{ ProjectName } .csproj") ;
1104+
1105+ // Create a package with a .targets file that logs an error
1106+ var packageX = new SimpleTestPackageContext ( "PackageX" , "1.0.0" ) ;
1107+ packageX . AddFile ( "lib/net5.0/_._" ) ;
1108+
1109+ var targetsContent = @"
1110+ <Project InitialTargets=""ErrorToFailBuild"">
1111+ <Target Name=""ErrorToFailBuild"">
1112+ <Error Text=""This is a failure within a package targets, to ensure list package is able to handle it."" />
1113+ </Target>
1114+ </Project>" ;
1115+ packageX . AddFile ( "build/PackageX.targets" , targetsContent ) ;
1116+
1117+ // Generate Package
1118+ await SimpleTestPackageUtility . CreateFolderFeedV3Async (
1119+ pathContext . PackageSource ,
1120+ PackageSaveMode . Defaultv3 ,
1121+ packageX ) ;
1122+
1123+ // Pre-Req
1124+ _fixture . RunDotnetExpectSuccess ( Directory . GetParent ( projectPath ) . FullName ,
1125+ $ "add { projectPath } package PackageX --version 1.0.0",
1126+ testOutputHelper : _testOutputHelper ) ;
1127+
1128+ // Act - dotnet list package should succeed despite the MSBuild error in the .targets file
1129+ CommandRunnerResult listResult = _fixture . RunDotnetExpectSuccess ( Directory . GetParent ( projectPath ) . FullName ,
1130+ $ "list { projectPath } package",
1131+ testOutputHelper : _testOutputHelper ) ;
1132+
1133+ // Assert - Verify the package is listed correctly
1134+ Assert . True ( ContainsIgnoringSpaces ( listResult . AllOutput , "PackageX1.0.01.0.0" ) ) ;
1135+ }
1136+
10971137 private static string CollapseSpaces ( string input )
10981138 {
10991139 return Regex . Replace ( input , " +" , " " ) ;
0 commit comments