@@ -58,7 +58,7 @@ public bool NoTypeReuse
58
58
internal const string WCFCSParamsFileName = "ConnectedService.json" ;
59
59
internal const string BaseServiceReferenceName = "ServiceReference" ;
60
60
61
- private static readonly List < string > s_cmdLineOverwriteSwitches = new List < string > { Switches . NoLogo . Name , Switches . Verbosity . Name , Switches . ToolContext . Name , Switches . ProjectFile . Name , Switches . AcceptCertificate . Name , Switches . ServiceContract . Name } ;
61
+ private static readonly List < string > s_cmdLineOverwriteSwitches = new List < string > { Switches . NoLogo . Name , Switches . Verbosity . Name , Switches . ToolContext . Name , Switches . ProjectFile . Name , Switches . AcceptCertificate . Name , Switches . ServiceContract . Name , Switches . Language . Name } ;
62
62
63
63
internal class CommandSwitches
64
64
{
@@ -92,6 +92,7 @@ internal class CommandSwitches
92
92
public readonly CommandSwitch Wrapped = new CommandSwitch ( WrappedKey , "wr" , SwitchType . Flag ) ;
93
93
public readonly CommandSwitch AcceptCertificate = new CommandSwitch ( AccecptCertificateKey , "ac" , SwitchType . Flag ) ;
94
94
public readonly CommandSwitch ServiceContract = new CommandSwitch ( ServiceContractKey , "sc" , SwitchType . Flag ) ;
95
+ public readonly CommandSwitch Language = new CommandSwitch ( LanguageKey , "l" , SwitchType . SingletonValue , OperationalContext . Global ) ;
95
96
96
97
public void Init ( ) { } // provided as a way to get the static class Switches loaded early.
97
98
}
@@ -198,13 +199,13 @@ public async Task ResolveAsync(CancellationToken cancellationToken)
198
199
{
199
200
if ( this . Help != true && this . Errors . Count ( ) == 0 )
200
201
{
201
- ProcessLanguageOption ( ) ;
202
-
203
202
ProcessSerializerOption ( ) ;
204
203
205
204
// process project file first as it can define the working directory.
206
205
await ProcessProjectFileOptionAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
207
206
207
+ ProcessLanguageOption ( ) ;
208
+
208
209
// next update option as the options may change.
209
210
await ProcessUpdateOptionAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
210
211
@@ -330,27 +331,32 @@ private async Task ProcessProjectFileOptionAsync(CancellationToken cancellationT
330
331
using ( SafeLogger logger = await SafeLogger . WriteStartOperationAsync ( this . Logger , $ "Resolving { ProjectFileKey } option ...") . ConfigureAwait ( false ) )
331
332
{
332
333
// Resolve the project in the current directory.
333
-
334
334
var workingDirectory = Directory . GetCurrentDirectory ( ) ;
335
- var projects = Directory . GetFiles ( workingDirectory , "*.csproj" , SearchOption . TopDirectoryOnly ) ;
335
+ var csProjects = Directory . GetFiles ( workingDirectory , "*.csproj" , SearchOption . TopDirectoryOnly ) ;
336
+ var vbProjects = Directory . GetFiles ( workingDirectory , "*.vbproj" , SearchOption . TopDirectoryOnly ) ;
336
337
337
- if ( projects . Length == 1 )
338
+ if ( csProjects . Length == 1 && vbProjects . Length == 0 )
339
+ {
340
+ projectFile = csProjects [ 0 ] ;
341
+ }
342
+ else if ( csProjects . Length == 0 && vbProjects . Length == 1 )
338
343
{
339
- projectFile = projects [ 0 ] ;
344
+ projectFile = vbProjects [ 0 ] ;
345
+ this . Language = "VisualBasic" ;
340
346
}
341
- else if ( projects . Length == 0 )
347
+ else if ( csProjects . Length == 0 && vbProjects . Length == 0 )
342
348
{
343
349
if ( this . ToolContext == OperationalContext . Project )
344
350
{
345
351
throw new ToolArgumentException ( string . Format ( CultureInfo . CurrentCulture , SR . ErrInvalidOperationNoProjectFileFoundUnderFolderFormat , workingDirectory ) ) ;
346
352
}
347
353
}
348
- else if ( projects . Length > 1 )
354
+ else
349
355
{
350
356
var moreThanOneProjectMsg = string . Format ( CultureInfo . CurrentCulture , SR . ErrMoreThanOneProjectFoundFormat , workingDirectory ) ;
351
357
if ( this . ToolContext != OperationalContext . Project )
352
358
{
353
- var projectItems = projects . Aggregate ( ( projectMsg , projectItem ) => $ "{ projectMsg } , { projectItem } ") . Trim ( ',' ) . Trim ( ) ;
359
+ var projectItems = csProjects . Concat ( vbProjects ) . ToArray ( ) . Aggregate ( ( projectMsg , projectItem ) => $ "{ projectMsg } , { projectItem } ") . Trim ( ',' ) . Trim ( ) ;
354
360
var useProjectOptions = string . Format ( CultureInfo . CurrentCulture , SR . UseProjectFileOptionOnMultipleFilesMsgFormat , Switches . ProjectFile . Name , projectItems ) ;
355
361
throw new ToolArgumentException ( $ "{ moreThanOneProjectMsg } { Environment . NewLine } { useProjectOptions } ") ;
356
362
}
@@ -417,7 +423,7 @@ private async Task ProcessOutputFileOptionAsync(string workingDirectory, Cancell
417
423
var outputFile = this . OutputFile ? . OriginalPath ( ) ;
418
424
if ( outputFile == null )
419
425
{
420
- outputFile = "Reference.cs " ;
426
+ outputFile = "Reference" ;
421
427
}
422
428
423
429
if ( ! outputFile . EndsWith ( this . CodeProvider . FileExtension , RuntimeEnvironmentHelper . FileStringComparison ) )
@@ -740,9 +746,20 @@ private void ProcessSerializerOption()
740
746
741
747
private void ProcessLanguageOption ( )
742
748
{
743
- if ( this . CodeProvider == null )
749
+ if ( ! string . IsNullOrEmpty ( Language ) )
750
+ {
751
+ try
752
+ {
753
+ CodeProvider = CodeDomProvider . CreateProvider ( Language ) ;
754
+ }
755
+ catch ( Exception e )
756
+ {
757
+ throw new ToolArgumentException ( string . Format ( SR . ErrCouldNotCreateCodeProvider , Language , Switches . Language . Abbreviation ) , e ) ;
758
+ }
759
+ }
760
+ else
744
761
{
745
- this . CodeProvider = CodeDomProvider . CreateProvider ( "csharp" ) ;
762
+ CodeProvider = CodeDomProvider . CreateProvider ( "csharp" ) ;
746
763
}
747
764
}
748
765
#endregion
0 commit comments