@@ -698,7 +698,7 @@ Resource not found
698
698
}
699
699
700
700
[ Fact ]
701
- public void NoRestore ( )
701
+ public void NoRestore_01 ( )
702
702
{
703
703
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
704
704
var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
@@ -729,6 +729,43 @@ public void NoRestore()
729
729
. And . HaveStdOut ( "Hello from Program" ) ;
730
730
}
731
731
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
+
732
769
[ Fact ]
733
770
public void NoBuild_01 ( )
734
771
{
@@ -1128,12 +1165,6 @@ public void UpToDate_InvalidOptions()
1128
1165
. Execute ( )
1129
1166
. Should ( ) . Fail ( )
1130
1167
. 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 ) ) ;
1137
1168
}
1138
1169
1139
1170
private static string ToJson ( string s ) => JsonSerializer . Serialize ( s ) ;
0 commit comments