From f77ee9a4d7103aa1a4fe6da43f996fefb09f0405 Mon Sep 17 00:00:00 2001 From: dasMulli Date: Fri, 3 Aug 2018 03:05:55 +0200 Subject: [PATCH] Complete configurations based on project file if present. --- src/dotnet/CommonOptions.cs | 4 ++-- src/dotnet/MsbuildProject.cs | 7 +++++++ src/dotnet/ProjectExtensions.cs | 5 +++++ src/dotnet/commands/dotnet-complete/Suggest.cs | 7 ++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index ed00f490b..e22796c2b 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -52,7 +52,7 @@ namespace Microsoft.DotNet.Cli description, Accept.ExactlyOneArgument() .With(name: CommonLocalizableStrings.ConfigurationArgumentName) - .WithSuggestionsFrom("Debug", "Release") + .WithSuggestionsFrom(_ => Suggest.ConfigurationsFromProjectFileOrDefaults()) .ForwardAsSingle(o => $"-property:Configuration={o.Arguments.Single()}")); public static Option VersionSuffixOption() => @@ -72,4 +72,4 @@ namespace Microsoft.DotNet.Cli CommonLocalizableStrings.NoRestoreDescription, Accept.NoArguments()); } -} \ No newline at end of file +} diff --git a/src/dotnet/MsbuildProject.cs b/src/dotnet/MsbuildProject.cs index 34055cacc..631a01c2f 100644 --- a/src/dotnet/MsbuildProject.cs +++ b/src/dotnet/MsbuildProject.cs @@ -25,6 +25,7 @@ namespace Microsoft.DotNet.Tools private ProjectCollection _projects; private List _cachedTfms = null; private IEnumerable cachedRuntimeIdentifiers; + private IEnumerable cachedConfigurations; private MsbuildProject(ProjectCollection projects, ProjectRootElement project) { @@ -168,6 +169,12 @@ namespace Microsoft.DotNet.Tools return _cachedTfms; } + public IEnumerable GetConfigurations() + { + return cachedConfigurations ?? + (cachedConfigurations = GetEvaluatedProject().GetConfigurations()); + } + public bool CanWorkOnFramework(NuGetFramework framework) { foreach (var tfm in GetTargetFrameworks()) diff --git a/src/dotnet/ProjectExtensions.cs b/src/dotnet/ProjectExtensions.cs index ab5065383..8037431d3 100644 --- a/src/dotnet/ProjectExtensions.cs +++ b/src/dotnet/ProjectExtensions.cs @@ -32,6 +32,11 @@ namespace Microsoft.DotNet.Tools.ProjectExtensions .Select((frameworkString) => NuGetFramework.Parse(frameworkString)); } + public static IEnumerable GetConfigurations(this Project project) + { + return project.GetPropertyCommaSeparatedValues("Configurations"); + } + public static IEnumerable GetPropertyCommaSeparatedValues(this Project project, string propertyName) { return project.GetPropertyValue(propertyName) diff --git a/src/dotnet/commands/dotnet-complete/Suggest.cs b/src/dotnet/commands/dotnet-complete/Suggest.cs index e9dd0c7ef..08a6a1373 100644 --- a/src/dotnet/commands/dotnet-complete/Suggest.cs +++ b/src/dotnet/commands/dotnet-complete/Suggest.cs @@ -40,6 +40,11 @@ namespace Microsoft.DotNet.Cli .Select(r => r.Include) ?? Empty(); + public static IEnumerable ConfigurationsFromProjectFileOrDefaults() => + GetMSBuildProject() + ?.GetConfigurations() ?? + new[] { "Debug", "Release" }; + private static MsbuildProject GetMSBuildProject() { try @@ -55,4 +60,4 @@ namespace Microsoft.DotNet.Cli } } } -} \ No newline at end of file +}