@@ -719,7 +719,7 @@ Resource not found
719
719
}
720
720
721
721
[ Fact ]
722
- public void NoRestore ( )
722
+ public void NoRestore_01 ( )
723
723
{
724
724
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
725
725
var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
@@ -750,6 +750,43 @@ public void NoRestore()
750
750
. And . HaveStdOut ( "Hello from Program" ) ;
751
751
}
752
752
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
+
753
790
[ Fact ]
754
791
public void NoBuild_01 ( )
755
792
{
@@ -1168,12 +1205,6 @@ public void UpToDate_InvalidOptions()
1168
1205
. Execute ( )
1169
1206
. Should ( ) . Fail ( )
1170
1207
. 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 ) ) ;
1177
1208
}
1178
1209
1179
1210
private static string ToJson ( string s ) => JsonSerializer . Serialize ( s ) ;
0 commit comments