@@ -698,7 +698,7 @@ Resource not found
698698 }
699699
700700 [ Fact ]
701- public void NoRestore ( )
701+ public void NoRestore_01 ( )
702702 {
703703 var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
704704 var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
@@ -729,6 +729,43 @@ public void NoRestore()
729729 . And . HaveStdOut ( "Hello from Program" ) ;
730730 }
731731
732+ [ Fact ]
733+ public void NoRestore_02 ( )
734+ {
735+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
736+ var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
737+ File . WriteAllText ( programFile , s_program ) ;
738+
739+ // Remove artifacts from possible previous runs of this test.
740+ var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programFile ) ;
741+ if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
742+
743+ // It is an error when never restored before.
744+ new DotnetCommand ( Log , "build" , "--no-restore" , "Program.cs" )
745+ . WithWorkingDirectory ( testInstance . Path )
746+ . Execute ( )
747+ . Should ( ) . Fail ( )
748+ . And . HaveStdOutContaining ( "NETSDK1004" ) ; // error NETSDK1004: Assets file '...\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.
749+
750+ // Run restore.
751+ new DotnetCommand ( Log , "restore" , "Program.cs" )
752+ . WithWorkingDirectory ( testInstance . Path )
753+ . Execute ( )
754+ . Should ( ) . Pass ( ) ;
755+
756+ // --no-restore works.
757+ new DotnetCommand ( Log , "build" , "--no-restore" , "Program.cs" )
758+ . WithWorkingDirectory ( testInstance . Path )
759+ . Execute ( )
760+ . Should ( ) . Pass ( ) ;
761+
762+ new DotnetCommand ( Log , "run" , "--no-build" , "Program.cs" )
763+ . WithWorkingDirectory ( testInstance . Path )
764+ . Execute ( )
765+ . Should ( ) . Pass ( )
766+ . And . HaveStdOut ( "Hello from Program" ) ;
767+ }
768+
732769 [ Fact ]
733770 public void NoBuild_01 ( )
734771 {
@@ -1128,12 +1165,6 @@ public void UpToDate_InvalidOptions()
11281165 . Execute ( )
11291166 . Should ( ) . Fail ( )
11301167 . And . HaveStdErrContaining ( string . Format ( CliCommandStrings . InvalidOptionCombination , RunCommandParser . NoCacheOption . Name , RunCommandParser . NoBuildOption . Name ) ) ;
1131-
1132- new DotnetCommand ( Log , "run" , "Program.cs" , "--no-cache" , "--no-restore" )
1133- . WithWorkingDirectory ( testInstance . Path )
1134- . Execute ( )
1135- . Should ( ) . Fail ( )
1136- . And . HaveStdErrContaining ( string . Format ( CliCommandStrings . InvalidOptionCombination , RunCommandParser . NoCacheOption . Name , RunCommandParser . NoRestoreOption . Name ) ) ;
11371168 }
11381169
11391170 private static string ToJson ( string s ) => JsonSerializer . Serialize ( s ) ;
0 commit comments