Skip to content

dotnet-svcutil VB support and add test. #5386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions src/dotnet-svcutil/lib/src/CommandProcessorOptions.cs
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public bool NoTypeReuse
internal const string WCFCSParamsFileName = "ConnectedService.json";
internal const string BaseServiceReferenceName = "ServiceReference";

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

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

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

ProcessSerializerOption();

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

ProcessLanguageOption();

// next update option as the options may change.
await ProcessUpdateOptionAsync(cancellationToken).ConfigureAwait(false);

@@ -330,27 +331,32 @@ private async Task ProcessProjectFileOptionAsync(CancellationToken cancellationT
using (SafeLogger logger = await SafeLogger.WriteStartOperationAsync(this.Logger, $"Resolving {ProjectFileKey} option ...").ConfigureAwait(false))
{
// Resolve the project in the current directory.

var workingDirectory = Directory.GetCurrentDirectory();
var projects = Directory.GetFiles(workingDirectory, "*.csproj", SearchOption.TopDirectoryOnly);
var csProjects = Directory.GetFiles(workingDirectory, "*.csproj", SearchOption.TopDirectoryOnly);
var vbProjects = Directory.GetFiles(workingDirectory, "*.vbproj", SearchOption.TopDirectoryOnly);

if (projects.Length == 1)
if(csProjects.Length == 1 && vbProjects.Length ==0 )
{
projectFile = csProjects[0];
}
else if (csProjects.Length == 0 && vbProjects.Length == 1)
{
projectFile = projects[0];
projectFile = vbProjects[0];
this.Language = "VisualBasic";
}
else if (projects.Length == 0)
else if(csProjects.Length == 0 && vbProjects.Length == 0)
{
if (this.ToolContext == OperationalContext.Project)
{
throw new ToolArgumentException(string.Format(CultureInfo.CurrentCulture, SR.ErrInvalidOperationNoProjectFileFoundUnderFolderFormat, workingDirectory));
}
}
else if (projects.Length > 1)
else
{
var moreThanOneProjectMsg = string.Format(CultureInfo.CurrentCulture, SR.ErrMoreThanOneProjectFoundFormat, workingDirectory);
if (this.ToolContext != OperationalContext.Project)
{
var projectItems = projects.Aggregate((projectMsg, projectItem) => $"{projectMsg}, {projectItem}").Trim(',').Trim();
var projectItems = csProjects.Concat(vbProjects).ToArray().Aggregate((projectMsg, projectItem) => $"{projectMsg}, {projectItem}").Trim(',').Trim();
var useProjectOptions = string.Format(CultureInfo.CurrentCulture, SR.UseProjectFileOptionOnMultipleFilesMsgFormat, Switches.ProjectFile.Name, projectItems);
throw new ToolArgumentException($"{moreThanOneProjectMsg}{Environment.NewLine}{useProjectOptions}");
}
@@ -417,7 +423,7 @@ private async Task ProcessOutputFileOptionAsync(string workingDirectory, Cancell
var outputFile = this.OutputFile?.OriginalPath();
if (outputFile == null)
{
outputFile = "Reference.cs";
outputFile = "Reference";
}

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

private void ProcessLanguageOption()
{
if (this.CodeProvider == null)
if (!string.IsNullOrEmpty(Language))
{
try
{
CodeProvider = CodeDomProvider.CreateProvider(Language);
}
catch (Exception e)
{
throw new ToolArgumentException(string.Format(SR.ErrCouldNotCreateCodeProvider, Language, Switches.Language.Abbreviation), e);
}
}
else
{
this.CodeProvider = CodeDomProvider.CreateProvider("csharp");
CodeProvider = CodeDomProvider.CreateProvider("csharp");
}
}
#endregion
Original file line number Diff line number Diff line change
@@ -38,6 +38,17 @@ internal CodeDomCompilationConfiguration()
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions[RedistVersionInfo.NameTag] = RedistVersionInfo.DefaultVersion;
AddCompilerInfo(compilerInfo);

// VB
compilerParameters = new CompilerParameters();
compilerParameters.WarningLevel = 4;
typeName = "Microsoft.VisualBasic.VBCodeProvider";
compilerInfo = new CompilerInfo(compilerParameters, typeName);
compilerInfo._compilerLanguages = new string[] { "vb", "vbs", "visualbasic", "vbscript" };
compilerInfo._compilerExtensions = new string[] { ".vb", "vb" };
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions[RedistVersionInfo.NameTag] = RedistVersionInfo.DefaultVersion;
AddCompilerInfo(compilerInfo);
}

private void AddCompilerInfo(CompilerInfo compilerInfo)
Loading
Oops, something went wrong.