@@ -878,6 +878,128 @@ public void DirectoryBuildProps()
878878 . And . HaveStdOut ( "Hello from TestName" ) ;
879879 }
880880
881+ /// <summary>
882+ /// Overriding default (implicit) properties of file-based apps via implicit build files.
883+ /// </summary>
884+ [ Fact ]
885+ public void DefaultProps_DirectoryBuildProps ( )
886+ {
887+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
888+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , """
889+ Console.WriteLine("Hi");
890+ """ ) ;
891+ File . WriteAllText ( Path . Join ( testInstance . Path , "Directory.Build.props" ) , """
892+ <Project>
893+ <PropertyGroup>
894+ <ImplicitUsings>disable</ImplicitUsings>
895+ </PropertyGroup>
896+ </Project>
897+ """ ) ;
898+
899+ new DotnetCommand ( Log , "run" , "Program.cs" )
900+ . WithWorkingDirectory ( testInstance . Path )
901+ . Execute ( )
902+ . Should ( ) . Fail ( )
903+ // error CS0103: The name 'Console' does not exist in the current context
904+ . And . HaveStdOutContaining ( "error CS0103" ) ;
905+
906+ // Converting to a project should not change the behavior.
907+
908+ new DotnetCommand ( Log , "project" , "convert" , "Program.cs" )
909+ . WithWorkingDirectory ( testInstance . Path )
910+ . Execute ( )
911+ . Should ( ) . Pass ( ) ;
912+
913+ new DotnetCommand ( Log , "run" )
914+ . WithWorkingDirectory ( Path . Join ( testInstance . Path , "Program" ) )
915+ . Execute ( )
916+ . Should ( ) . Fail ( )
917+ // error CS0103: The name 'Console' does not exist in the current context
918+ . And . HaveStdOutContaining ( "error CS0103" ) ;
919+ }
920+
921+ /// <summary>
922+ /// Overriding default (implicit) properties of file-based apps from custom SDKs.
923+ /// </summary>
924+ [ Fact ]
925+ public void DefaultProps_CustomSdk ( )
926+ {
927+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
928+
929+ var sdkDir = Path . Join ( testInstance . Path , "MySdk" ) ;
930+ Directory . CreateDirectory ( sdkDir ) ;
931+ File . WriteAllText ( Path . Join ( sdkDir , "Sdk.props" ) , """
932+ <Project>
933+ <PropertyGroup>
934+ <ImplicitUsings>disable</ImplicitUsings>
935+ </PropertyGroup>
936+ </Project>
937+ """ ) ;
938+ File . WriteAllText ( Path . Join ( sdkDir , "Sdk.targets" ) , """
939+ <Project />
940+ """ ) ;
941+ File . WriteAllText ( Path . Join ( sdkDir , "MySdk.csproj" ) , $ """
942+ <Project Sdk="Microsoft.NET.Sdk">
943+ <PropertyGroup>
944+ <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
945+ <PackageType>MSBuildSdk</PackageType>
946+ <IncludeBuildOutput>false</IncludeBuildOutput>
947+ </PropertyGroup>
948+ <ItemGroup>
949+ <None Include="Sdk.*" Pack="true" PackagePath="Sdk" />
950+ </ItemGroup>
951+ </Project>
952+ """ ) ;
953+
954+ new DotnetCommand ( Log , "pack" )
955+ . WithWorkingDirectory ( sdkDir )
956+ . Execute ( )
957+ . Should ( ) . Pass ( ) ;
958+
959+ var appDir = Path . Join ( testInstance . Path , "app" ) ;
960+ Directory . CreateDirectory ( appDir ) ;
961+ File . WriteAllText ( Path . Join ( appDir , "NuGet.config" ) , $ """
962+ <configuration>
963+ <packageSources>
964+ <add key="local" value="{ Path . Join ( sdkDir , "bin" , "Release" ) } " />
965+ <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
966+ </packageSources>
967+ </configuration>
968+ """ ) ;
969+ File . WriteAllText ( Path . Join ( appDir , "Program.cs" ) , """
970+ #:sdk Microsoft.NET.Sdk
971+ #:sdk MySdk@1.0.0
972+ Console.WriteLine("Hi");
973+ """ ) ;
974+
975+ // Use custom package cache to avoid reuse of the custom SDK packed by previous test runs.
976+ var packagesDir = Path . Join ( testInstance . Path , ".packages" ) ;
977+
978+ new DotnetCommand ( Log , "run" , "Program.cs" )
979+ . WithEnvironmentVariable ( "NUGET_PACKAGES" , packagesDir )
980+ . WithWorkingDirectory ( appDir )
981+ . Execute ( )
982+ . Should ( ) . Fail ( )
983+ // error CS0103: The name 'Console' does not exist in the current context
984+ . And . HaveStdOutContaining ( "error CS0103" ) ;
985+
986+ // Converting to a project should not change the behavior.
987+
988+ new DotnetCommand ( Log , "project" , "convert" , "Program.cs" )
989+ . WithEnvironmentVariable ( "NUGET_PACKAGES" , packagesDir )
990+ . WithWorkingDirectory ( appDir )
991+ . Execute ( )
992+ . Should ( ) . Pass ( ) ;
993+
994+ new DotnetCommand ( Log , "run" )
995+ . WithEnvironmentVariable ( "NUGET_PACKAGES" , packagesDir )
996+ . WithWorkingDirectory ( Path . Join ( appDir , "Program" ) )
997+ . Execute ( )
998+ . Should ( ) . Fail ( )
999+ // error CS0103: The name 'Console' does not exist in the current context
1000+ . And . HaveStdOutContaining ( "error CS0103" ) ;
1001+ }
1002+
8811003 [ Fact ]
8821004 public void ComputeRunArguments_Success ( )
8831005 {
@@ -3441,6 +3563,14 @@ public void Api()
34413563 <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
34423564 <PackageOutputPath>artifacts/$(MSBuildProjectName)</PackageOutputPath>
34433565 <FileBasedProgram>true</FileBasedProgram>
3566+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
3567+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3568+ <OutputType>Exe</OutputType>
3569+ <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
3570+ <ImplicitUsings>enable</ImplicitUsings>
3571+ <Nullable>enable</Nullable>
3572+ <PublishAot>true</PublishAot>
3573+ <PackAsTool>true</PackAsTool>
34443574 </PropertyGroup>
34453575
34463576 <ItemGroup>
@@ -3451,16 +3581,9 @@ public void Api()
34513581 <Import Project="Sdk.props" Sdk="Aspire.Hosting.Sdk" Version="9.1.0" />
34523582
34533583 <PropertyGroup>
3454- <OutputType>Exe</OutputType>
3455- <ImplicitUsings>enable</ImplicitUsings>
3456- <Nullable>enable</Nullable>
3457- <PublishAot>true</PublishAot>
3458- <PackAsTool>true</PackAsTool>
3459- <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
3460- <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3461- <RestoreUseStaticGraphEvaluation>false</RestoreUseStaticGraphEvaluation>
34623584 <TargetFramework>net11.0</TargetFramework>
34633585 <LangVersion>preview</LangVersion>
3586+ <RestoreUseStaticGraphEvaluation>false</RestoreUseStaticGraphEvaluation>
34643587 <Features>$(Features);FileBasedProgram</Features>
34653588 </PropertyGroup>
34663589
@@ -3512,6 +3635,14 @@ public void Api_Diagnostic_01()
35123635 <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
35133636 <PackageOutputPath>artifacts/$(MSBuildProjectName)</PackageOutputPath>
35143637 <FileBasedProgram>true</FileBasedProgram>
3638+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
3639+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3640+ <OutputType>Exe</OutputType>
3641+ <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
3642+ <ImplicitUsings>enable</ImplicitUsings>
3643+ <Nullable>enable</Nullable>
3644+ <PublishAot>true</PublishAot>
3645+ <PackAsTool>true</PackAsTool>
35153646 </PropertyGroup>
35163647
35173648 <ItemGroup>
@@ -3521,14 +3652,6 @@ public void Api_Diagnostic_01()
35213652 <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
35223653
35233654 <PropertyGroup>
3524- <OutputType>Exe</OutputType>
3525- <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
3526- <ImplicitUsings>enable</ImplicitUsings>
3527- <Nullable>enable</Nullable>
3528- <PublishAot>true</PublishAot>
3529- <PackAsTool>true</PackAsTool>
3530- <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
3531- <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
35323655 <RestoreUseStaticGraphEvaluation>false</RestoreUseStaticGraphEvaluation>
35333656 <Features>$(Features);FileBasedProgram</Features>
35343657 </PropertyGroup>
@@ -3580,6 +3703,14 @@ public void Api_Diagnostic_02()
35803703 <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
35813704 <PackageOutputPath>artifacts/$(MSBuildProjectName)</PackageOutputPath>
35823705 <FileBasedProgram>true</FileBasedProgram>
3706+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
3707+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3708+ <OutputType>Exe</OutputType>
3709+ <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
3710+ <ImplicitUsings>enable</ImplicitUsings>
3711+ <Nullable>enable</Nullable>
3712+ <PublishAot>true</PublishAot>
3713+ <PackAsTool>true</PackAsTool>
35833714 </PropertyGroup>
35843715
35853716 <ItemGroup>
@@ -3589,14 +3720,6 @@ public void Api_Diagnostic_02()
35893720 <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
35903721
35913722 <PropertyGroup>
3592- <OutputType>Exe</OutputType>
3593- <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
3594- <ImplicitUsings>enable</ImplicitUsings>
3595- <Nullable>enable</Nullable>
3596- <PublishAot>true</PublishAot>
3597- <PackAsTool>true</PackAsTool>
3598- <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
3599- <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
36003723 <RestoreUseStaticGraphEvaluation>false</RestoreUseStaticGraphEvaluation>
36013724 <Features>$(Features);FileBasedProgram</Features>
36023725 </PropertyGroup>
0 commit comments