Skip to content

Commit cd86c2d

Browse files
committed
dotnet-svcutil VB support and add test.
1 parent 8941cb3 commit cd86c2d

27 files changed

+4203
-16
lines changed

src/dotnet-svcutil/lib/src/CommandProcessorOptions.cs

+30-13
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public bool NoTypeReuse
5858
internal const string WCFCSParamsFileName = "ConnectedService.json";
5959
internal const string BaseServiceReferenceName = "ServiceReference";
6060

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 };
6262

6363
internal class CommandSwitches
6464
{
@@ -92,6 +92,7 @@ internal class CommandSwitches
9292
public readonly CommandSwitch Wrapped = new CommandSwitch(WrappedKey, "wr", SwitchType.Flag);
9393
public readonly CommandSwitch AcceptCertificate = new CommandSwitch(AccecptCertificateKey, "ac", SwitchType.Flag);
9494
public readonly CommandSwitch ServiceContract = new CommandSwitch(ServiceContractKey, "sc", SwitchType.Flag);
95+
public readonly CommandSwitch Language = new CommandSwitch(LanguageKey, "l", SwitchType.SingletonValue, OperationalContext.Global);
9596

9697
public void Init() { } // provided as a way to get the static class Switches loaded early.
9798
}
@@ -198,13 +199,13 @@ public async Task ResolveAsync(CancellationToken cancellationToken)
198199
{
199200
if (this.Help != true && this.Errors.Count() == 0)
200201
{
201-
ProcessLanguageOption();
202-
203202
ProcessSerializerOption();
204203

205204
// process project file first as it can define the working directory.
206205
await ProcessProjectFileOptionAsync(cancellationToken).ConfigureAwait(false);
207206

207+
ProcessLanguageOption();
208+
208209
// next update option as the options may change.
209210
await ProcessUpdateOptionAsync(cancellationToken).ConfigureAwait(false);
210211

@@ -330,27 +331,32 @@ private async Task ProcessProjectFileOptionAsync(CancellationToken cancellationT
330331
using (SafeLogger logger = await SafeLogger.WriteStartOperationAsync(this.Logger, $"Resolving {ProjectFileKey} option ...").ConfigureAwait(false))
331332
{
332333
// Resolve the project in the current directory.
333-
334334
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);
336337

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)
338343
{
339-
projectFile = projects[0];
344+
projectFile = vbProjects[0];
345+
this.Language = "VisualBasic";
340346
}
341-
else if (projects.Length == 0)
347+
else if(csProjects.Length == 0 && vbProjects.Length == 0)
342348
{
343349
if (this.ToolContext == OperationalContext.Project)
344350
{
345351
throw new ToolArgumentException(string.Format(CultureInfo.CurrentCulture, SR.ErrInvalidOperationNoProjectFileFoundUnderFolderFormat, workingDirectory));
346352
}
347353
}
348-
else if (projects.Length > 1)
354+
else
349355
{
350356
var moreThanOneProjectMsg = string.Format(CultureInfo.CurrentCulture, SR.ErrMoreThanOneProjectFoundFormat, workingDirectory);
351357
if (this.ToolContext != OperationalContext.Project)
352358
{
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();
354360
var useProjectOptions = string.Format(CultureInfo.CurrentCulture, SR.UseProjectFileOptionOnMultipleFilesMsgFormat, Switches.ProjectFile.Name, projectItems);
355361
throw new ToolArgumentException($"{moreThanOneProjectMsg}{Environment.NewLine}{useProjectOptions}");
356362
}
@@ -417,7 +423,7 @@ private async Task ProcessOutputFileOptionAsync(string workingDirectory, Cancell
417423
var outputFile = this.OutputFile?.OriginalPath();
418424
if (outputFile == null)
419425
{
420-
outputFile = "Reference.cs";
426+
outputFile = "Reference";
421427
}
422428

423429
if (!outputFile.EndsWith(this.CodeProvider.FileExtension, RuntimeEnvironmentHelper.FileStringComparison))
@@ -740,9 +746,20 @@ private void ProcessSerializerOption()
740746

741747
private void ProcessLanguageOption()
742748
{
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
744761
{
745-
this.CodeProvider = CodeDomProvider.CreateProvider("csharp");
762+
CodeProvider = CodeDomProvider.CreateProvider("csharp");
746763
}
747764
}
748765
#endregion

src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.CodeDom/Configuration/CodeDomCompilationConfiguration.cs

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ internal CodeDomCompilationConfiguration()
3838
compilerInfo._providerOptions = new Dictionary<string, string>();
3939
compilerInfo._providerOptions[RedistVersionInfo.NameTag] = RedistVersionInfo.DefaultVersion;
4040
AddCompilerInfo(compilerInfo);
41+
42+
// VB
43+
compilerParameters = new CompilerParameters();
44+
compilerParameters.WarningLevel = 4;
45+
typeName = "Microsoft.VisualBasic.VBCodeProvider";
46+
compilerInfo = new CompilerInfo(compilerParameters, typeName);
47+
compilerInfo._compilerLanguages = new string[] { "vb", "vbs", "visualbasic", "vbscript" };
48+
compilerInfo._compilerExtensions = new string[] { ".vb", "vb" };
49+
compilerInfo._providerOptions = new Dictionary<string, string>();
50+
compilerInfo._providerOptions[RedistVersionInfo.NameTag] = RedistVersionInfo.DefaultVersion;
51+
AddCompilerInfo(compilerInfo);
4152
}
4253

4354
private void AddCompilerInfo(CompilerInfo compilerInfo)

0 commit comments

Comments
 (0)