@@ -85,6 +85,29 @@ public async Task InternalsVisibleTo_DoNotRegenerateExtensionMethods()
8585
8686 }
8787
88+ [ Fact ]
89+ public async Task InternalsVisibleTo_TwoReferencedAssemblies_DoNotCauseAmbiguity ( )
90+ {
91+ var assemblies = await NuGetHelpers . GetNuGetReferences ( "NETStandard.Library" , "2.0.3" , "build/" ) ;
92+
93+ // Generate two assemblies that both expose internals to "main"
94+ var proj2Generation = GenerateFiles ( """[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("main")]""" , assemblyName : "proj2" , assemblyLocations : assemblies ) ;
95+ Assert . Single ( GetFileNames ( proj2Generation . GeneratorResult ) , file => file is "T_System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.g.cs" ) ;
96+
97+ var proj3Generation = GenerateFiles ( """[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("main")]""" , assemblyName : "proj3" , assemblyLocations : assemblies ) ;
98+ Assert . Single ( GetFileNames ( proj3Generation . GeneratorResult ) , file => file is "T_System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.g.cs" ) ;
99+
100+ var proj2Dll = Path . GetTempFileName ( ) + ".dll" ;
101+ var proj3Dll = Path . GetTempFileName ( ) + ".dll" ;
102+ await File . WriteAllBytesAsync ( proj2Dll , proj2Generation . Assembly ! ) ;
103+ await File . WriteAllBytesAsync ( proj3Dll , proj3Generation . Assembly ! ) ;
104+
105+ // "main" references both assemblies. The generator must still produce types
106+ // that would otherwise be ambiguous (CS0433) between proj2 and proj3.
107+ var result = GenerateFiles ( "" , assemblyName : "main" , assemblyLocations : assemblies . Append ( proj2Dll ) . Append ( proj3Dll ) ) ;
108+ Assert . Single ( GetFileNames ( result . GeneratorResult ) , file => file is "T_System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.g.cs" ) ;
109+ }
110+
88111 [ Theory ]
89112 [ MemberData ( nameof ( GetConfigurations ) ) ]
90113 public async Task GeneratedCodeCompile ( PackageReference [ ] packages , bool allowUnsafe )
0 commit comments