@@ -30,6 +30,56 @@ static CompilationUtil()
3030
3131 public static IProviderOptions VBC2 { get ; }
3232
33+ internal static IProviderOptions CreateProviderOptions ( IDictionary < string , string > options , IProviderOptions baseOptions )
34+ {
35+ Dictionary < string , string > allOptions = null ;
36+
37+ // Copy the base options
38+ ProviderOptions providerOpts = new ProviderOptions ( baseOptions ) ;
39+
40+ // Update as necessary. Case-sensitive.
41+ foreach ( var option in options )
42+ {
43+ if ( String . IsNullOrWhiteSpace ( option . Key ) )
44+ continue ;
45+
46+ switch ( option . Key )
47+ {
48+ case "CompilerFullPath" :
49+ providerOpts . CompilerFullPath = option . Value ;
50+ break ;
51+
52+ case "CompilerServerTimeToLive" :
53+ if ( Int32 . TryParse ( option . Value , out int newTTL ) )
54+ providerOpts . CompilerServerTimeToLive = newTTL ;
55+ break ;
56+
57+ case "CompilerVersion" :
58+ providerOpts . CompilerVersion = option . Value ;
59+ break ;
60+
61+ case "WarnAsError" :
62+ if ( Boolean . TryParse ( option . Value , out bool warnAsError ) )
63+ providerOpts . WarnAsError = warnAsError ;
64+ break ;
65+
66+ case "AllOptions" :
67+ allOptions = allOptions ?? new Dictionary < string , string > ( providerOpts . AllOptions ) ;
68+ allOptions . Remove ( option . Key ) ;
69+ allOptions . Add ( option . Key , option . Value ) ;
70+ break ;
71+
72+ default :
73+ break ;
74+ }
75+ }
76+
77+ if ( allOptions != null )
78+ providerOpts . AllOptions = allOptions ;
79+
80+ return providerOpts ;
81+ }
82+
3383 public static IProviderOptions GetProviderOptionsFor ( string fileExt )
3484 {
3585 //
@@ -48,10 +98,15 @@ public static IProviderOptions GetProviderOptionsFor(string fileExt)
4898 if ( String . IsNullOrEmpty ( compilerFullPath ) )
4999 compilerFullPath = CompilerDefaultPath ( ) ;
50100
51- if ( fileExt . Equals ( ".cs" , StringComparison . InvariantCultureIgnoreCase ) )
52- compilerFullPath = Path . Combine ( compilerFullPath , "csc.exe" ) ;
53- else if ( fileExt . Equals ( ".vb" , StringComparison . InvariantCultureIgnoreCase ) )
54- compilerFullPath = Path . Combine ( compilerFullPath , "vbc.exe" ) ;
101+ if ( ! String . IsNullOrWhiteSpace ( fileExt ) )
102+ {
103+ // If we have a file extension, try to infer the compiler to use
104+ // TODO: Should we also check compilerFullPath to assert it is a Directory and not a file?
105+ if ( fileExt . Equals ( ".cs" , StringComparison . InvariantCultureIgnoreCase ) || fileExt . Equals ( "cs" , StringComparison . InvariantCultureIgnoreCase ) )
106+ compilerFullPath = Path . Combine ( compilerFullPath , "csc.exe" ) ;
107+ else if ( fileExt . Equals ( ".vb" , StringComparison . InvariantCultureIgnoreCase ) || fileExt . Equals ( "vb" , StringComparison . InvariantCultureIgnoreCase ) )
108+ compilerFullPath = Path . Combine ( compilerFullPath , "vbc.exe" ) ;
109+ }
55110
56111
57112 //
@@ -61,7 +116,8 @@ public static IProviderOptions GetProviderOptionsFor(string fileExt)
61116 string ttlstr = Environment . GetEnvironmentVariable ( "VBCSCOMPILER_TTL" ) ;
62117 if ( String . IsNullOrEmpty ( ttlstr ) )
63118 options . TryGetValue ( "CompilerServerTTL" , out ttlstr ) ;
64- if ( ! Int32 . TryParse ( ttlstr , out ttl ) ) {
119+ if ( ! Int32 . TryParse ( ttlstr , out ttl ) )
120+ {
65121 ttl = DefaultCompilerServerTTL ;
66122
67123 if ( ! String . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "DEV_ENVIRONMENT" ) ) ||
@@ -82,7 +138,8 @@ public static IProviderOptions GetProviderOptionsFor(string fileExt)
82138 // WarnAsError - default false.
83139 //
84140 bool warnAsError = false ;
85- if ( options . TryGetValue ( "WarnAsError" , out string sWAE ) ) {
141+ if ( options . TryGetValue ( "WarnAsError" , out string sWAE ) )
142+ {
86143 Boolean . TryParse ( sWAE , out warnAsError ) ; // Failure to parse sets to 'false'
87144 }
88145
@@ -97,7 +154,8 @@ public static IProviderOptions GetProviderOptionsFor(string fileExt)
97154 useAspNetSettings = true ;
98155 }
99156
100- ProviderOptions providerOptions = new ProviderOptions ( ) {
157+ ProviderOptions providerOptions = new ProviderOptions ( )
158+ {
101159 CompilerFullPath = compilerFullPath ,
102160 CompilerServerTimeToLive = ttl ,
103161 CompilerVersion = compilerVersion ,
0 commit comments