@@ -3034,6 +3034,27 @@ public void CscOnly_SpacesInPath()
3034
3034
Build ( testInstance , BuildLevel . Csc , expectedOutput : "v1" , programFileName : programFileName ) ;
3035
3035
}
3036
3036
3037
+ [ Fact ] // https://github.com/dotnet/sdk/issues/50778
3038
+ public void CscOnly_Args ( )
3039
+ {
3040
+ var testInstance = _testAssetsManager . CreateTestDirectory ( baseDirectory : OutOfTreeBaseDirectory ) ;
3041
+ var programPath = Path . Join ( testInstance . Path , "Program.cs" ) ;
3042
+ File . WriteAllText ( programPath , s_program ) ;
3043
+
3044
+ // Remove artifacts from possible previous runs of this test.
3045
+ var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programPath ) ;
3046
+ if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
3047
+
3048
+ Build ( testInstance , BuildLevel . Csc , args : [ "test" , "args" ] , expectedOutput : """
3049
+ echo args:test;args
3050
+ Hello from Program
3051
+ """ ) ;
3052
+ }
3053
+
3054
+ /// <summary>
3055
+ /// Tests an optimization which remembers CSC args from prior MSBuild runs and can skip subsequent MSBuild invocations and call CSC directly.
3056
+ /// This optimization kicks in when the file has some <c>#:</c> directives (then the simpler "hard-coded CSC args" optimization cannot be used).
3057
+ /// </summary>
3037
3058
[ Fact ]
3038
3059
public void CscOnly_AfterMSBuild ( )
3039
3060
{
@@ -3089,6 +3110,9 @@ public void CscOnly_AfterMSBuild()
3089
3110
Build ( testInstance , BuildLevel . All , expectedOutput : "v4 " ) ;
3090
3111
}
3091
3112
3113
+ /// <summary>
3114
+ /// See <see cref="CscOnly_AfterMSBuild"/>.
3115
+ /// </summary>
3092
3116
[ Fact ]
3093
3117
public void CscOnly_AfterMSBuild_SpacesInPath ( )
3094
3118
{
@@ -3119,6 +3143,46 @@ public void CscOnly_AfterMSBuild_SpacesInPath()
3119
3143
Build ( testInstance , BuildLevel . Csc , expectedOutput : "v2 Release" , programFileName : programFileName ) ;
3120
3144
}
3121
3145
3146
+ /// <summary>
3147
+ /// See <see cref="CscOnly_AfterMSBuild"/>.
3148
+ /// </summary>
3149
+ [ Fact ]
3150
+ public void CscOnly_AfterMSBuild_Args ( )
3151
+ {
3152
+ var testInstance = _testAssetsManager . CreateTestDirectory ( baseDirectory : OutOfTreeBaseDirectory ) ;
3153
+ var programPath = Path . Join ( testInstance . Path , "Program.cs" ) ;
3154
+
3155
+ var code = $ """
3156
+ #:property Configuration=Release
3157
+ { s_program }
3158
+ """ ;
3159
+
3160
+ File . WriteAllText ( programPath , code ) ;
3161
+
3162
+ // Remove artifacts from possible previous runs of this test.
3163
+ var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programPath ) ;
3164
+ if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
3165
+
3166
+ Build ( testInstance , BuildLevel . All , args : [ "test" , "args" ] , expectedOutput : """
3167
+ echo args:test;args
3168
+ Hello from Program
3169
+ Release config
3170
+ """ ) ;
3171
+
3172
+ code = code . Replace ( "Hello" , "Hi" ) ;
3173
+ File . WriteAllText ( programPath , code ) ;
3174
+
3175
+ Build ( testInstance , BuildLevel . Csc , [ "test" , "args" ] , expectedOutput : """
3176
+ echo args:test;args
3177
+ Hi from Program
3178
+ Release config
3179
+ """ ) ;
3180
+ }
3181
+
3182
+ /// <summary>
3183
+ /// See <see cref="CscOnly_AfterMSBuild"/>.
3184
+ /// This optimization currently does not support <c>#:project</c> references and hence is disabled if those are present.
3185
+ /// </summary>
3122
3186
[ Fact ]
3123
3187
public void CscOnly_AfterMSBuild_ProjectReferences ( )
3124
3188
{
@@ -3175,8 +3239,8 @@ public class LibClass
3175
3239
}
3176
3240
3177
3241
/// <summary>
3178
- /// If users have more complex build customizations, they can opt out of the optimization which
3179
- /// reuses CSC arguments and skips subsequent MSBuild invocations .
3242
+ /// See <see cref="CscOnly_AfterMSBuild"/>.
3243
+ /// If users have more complex build customizations, they can opt out of the optimization .
3180
3244
/// </summary>
3181
3245
[ Theory , CombinatorialData ]
3182
3246
public void CscOnly_AfterMSBuild_OptOut ( bool canSkipMSBuild , bool inDirectoryBuildProps )
@@ -3220,6 +3284,9 @@ public void CscOnly_AfterMSBuild_OptOut(bool canSkipMSBuild, bool inDirectoryBui
3220
3284
Build ( testInstance , canSkipMSBuild ? BuildLevel . Csc : BuildLevel . All , expectedOutput : "v2 Release" ) ;
3221
3285
}
3222
3286
3287
+ /// <summary>
3288
+ /// See <see cref="CscOnly_AfterMSBuild"/>.
3289
+ /// </summary>
3223
3290
[ Fact ]
3224
3291
public void CscOnly_AfterMSBuild_AuxiliaryFilesNotReused ( )
3225
3292
{
0 commit comments