@@ -726,6 +726,7 @@ public void ClassLibrary_EntryPointFileDoesNotExist()
726726
727727 /// <summary>
728728 /// Other files in the folder are not part of the compilation.
729+ /// See <see href="https://github.com/dotnet/sdk/issues/51785"/>.
729730 /// </summary>
730731 [ Fact ]
731732 public void MultipleFiles_RunEntryPoint ( )
@@ -750,9 +751,32 @@ public void MultipleFiles_RunEntryPoint()
750751 . WithWorkingDirectory ( testInstance . Path )
751752 . Execute ( )
752753 . Should ( ) . Pass ( )
753- // warning CS2002: Source file 'Program.cs' specified multiple times
754- . And . HaveStdOutContaining ( "warning CS2002" )
755- . And . HaveStdOutContaining ( "Hello, String from Util" ) ;
754+ . And . HaveStdOut ( "Hello, String from Util" ) ;
755+ }
756+
757+ /// <summary>
758+ /// Setting EnableDefaultCompileItems=true via Directory.Build.props should not cause CS2002 warning.
759+ /// See <see href="https://github.com/dotnet/sdk/issues/51785"/>.
760+ /// </summary>
761+ [ Fact ]
762+ public void MultipleFiles_EnableDefaultCompileItemsViaDirectoryBuildProps ( )
763+ {
764+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
765+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programDependingOnUtil ) ;
766+ File . WriteAllText ( Path . Join ( testInstance . Path , "Util.cs" ) , s_util ) ;
767+ File . WriteAllText ( Path . Join ( testInstance . Path , "Directory.Build.props" ) , """
768+ <Project>
769+ <PropertyGroup>
770+ <EnableDefaultCompileItems>true</EnableDefaultCompileItems>
771+ </PropertyGroup>
772+ </Project>
773+ """ ) ;
774+
775+ new DotnetCommand ( Log , "run" , "Program.cs" )
776+ . WithWorkingDirectory ( testInstance . Path )
777+ . Execute ( )
778+ . Should ( ) . Pass ( )
779+ . And . HaveStdOut ( "Hello, String from Util" ) ;
756780 }
757781
758782 /// <summary>
@@ -3941,7 +3965,7 @@ public void Api()
39413965 </ItemGroup>
39423966
39433967 <ItemGroup>
3944- <Compile Include="{ programPath } " />
3968+ <Compile Condition="'$(EnableDefaultCompileItems)' != 'true'" Include="{ programPath } " />
39453969 </ItemGroup>
39463970
39473971 <ItemGroup>
@@ -4008,7 +4032,7 @@ public void Api_Diagnostic_01()
40084032 </PropertyGroup>
40094033
40104034 <ItemGroup>
4011- <Compile Include="{ programPath } " />
4035+ <Compile Condition="'$(EnableDefaultCompileItems)' != 'true'" Include="{ programPath } " />
40124036 </ItemGroup>
40134037
40144038 <ItemGroup>
@@ -4078,7 +4102,7 @@ public void Api_Diagnostic_02()
40784102 </PropertyGroup>
40794103
40804104 <ItemGroup>
4081- <Compile Include="{ programPath } " />
4105+ <Compile Condition="'$(EnableDefaultCompileItems)' != 'true'" Include="{ programPath } " />
40824106 </ItemGroup>
40834107
40844108 <ItemGroup>
0 commit comments