@@ -719,7 +719,7 @@ Resource not found
719719 }
720720
721721 [ Fact ]
722- public void NoRestore ( )
722+ public void NoRestore_01 ( )
723723 {
724724 var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
725725 var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
@@ -750,6 +750,43 @@ public void NoRestore()
750750 . And . HaveStdOut ( "Hello from Program" ) ;
751751 }
752752
753+ [ Fact ]
754+ public void NoRestore_02 ( )
755+ {
756+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
757+ var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
758+ File . WriteAllText ( programFile , s_program ) ;
759+
760+ // Remove artifacts from possible previous runs of this test.
761+ var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programFile ) ;
762+ if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
763+
764+ // It is an error when never restored before.
765+ new DotnetCommand ( Log , "build" , "--no-restore" , "Program.cs" )
766+ . WithWorkingDirectory ( testInstance . Path )
767+ . Execute ( )
768+ . Should ( ) . Fail ( )
769+ . And . HaveStdOutContaining ( "NETSDK1004" ) ; // error NETSDK1004: Assets file '...\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.
770+
771+ // Run restore.
772+ new DotnetCommand ( Log , "restore" , "Program.cs" )
773+ . WithWorkingDirectory ( testInstance . Path )
774+ . Execute ( )
775+ . Should ( ) . Pass ( ) ;
776+
777+ // --no-restore works.
778+ new DotnetCommand ( Log , "build" , "--no-restore" , "Program.cs" )
779+ . WithWorkingDirectory ( testInstance . Path )
780+ . Execute ( )
781+ . Should ( ) . Pass ( ) ;
782+
783+ new DotnetCommand ( Log , "run" , "--no-build" , "Program.cs" )
784+ . WithWorkingDirectory ( testInstance . Path )
785+ . Execute ( )
786+ . Should ( ) . Pass ( )
787+ . And . HaveStdOut ( "Hello from Program" ) ;
788+ }
789+
753790 [ Fact ]
754791 public void NoBuild_01 ( )
755792 {
@@ -1168,12 +1205,6 @@ public void UpToDate_InvalidOptions()
11681205 . Execute ( )
11691206 . Should ( ) . Fail ( )
11701207 . And . HaveStdErrContaining ( string . Format ( CliCommandStrings . InvalidOptionCombination , RunCommandParser . NoCacheOption . Name , RunCommandParser . NoBuildOption . Name ) ) ;
1171-
1172- new DotnetCommand ( Log , "run" , "Program.cs" , "--no-cache" , "--no-restore" )
1173- . WithWorkingDirectory ( testInstance . Path )
1174- . Execute ( )
1175- . Should ( ) . Fail ( )
1176- . And . HaveStdErrContaining ( string . Format ( CliCommandStrings . InvalidOptionCombination , RunCommandParser . NoCacheOption . Name , RunCommandParser . NoRestoreOption . Name ) ) ;
11771208 }
11781209
11791210 private static string ToJson ( string s ) => JsonSerializer . Serialize ( s ) ;
0 commit comments