Merge pull request #9788 from dasMulli/feature/complete-suggest-configurations

Complete configurations based on project file if present.
This commit is contained in:
Livar 2018-08-07 13:17:31 -07:00 committed by GitHub
commit 8ca823bfd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 3 deletions

View file

@ -52,7 +52,7 @@ namespace Microsoft.DotNet.Cli
description, description,
Accept.ExactlyOneArgument() Accept.ExactlyOneArgument()
.With(name: CommonLocalizableStrings.ConfigurationArgumentName) .With(name: CommonLocalizableStrings.ConfigurationArgumentName)
.WithSuggestionsFrom("Debug", "Release") .WithSuggestionsFrom(_ => Suggest.ConfigurationsFromProjectFileOrDefaults())
.ForwardAsSingle(o => $"-property:Configuration={o.Arguments.Single()}")); .ForwardAsSingle(o => $"-property:Configuration={o.Arguments.Single()}"));
public static Option VersionSuffixOption() => public static Option VersionSuffixOption() =>
@ -72,4 +72,4 @@ namespace Microsoft.DotNet.Cli
CommonLocalizableStrings.NoRestoreDescription, CommonLocalizableStrings.NoRestoreDescription,
Accept.NoArguments()); Accept.NoArguments());
} }
} }

View file

@ -25,6 +25,7 @@ namespace Microsoft.DotNet.Tools
private ProjectCollection _projects; private ProjectCollection _projects;
private List<NuGetFramework> _cachedTfms = null; private List<NuGetFramework> _cachedTfms = null;
private IEnumerable<string> cachedRuntimeIdentifiers; private IEnumerable<string> cachedRuntimeIdentifiers;
private IEnumerable<string> cachedConfigurations;
private MsbuildProject(ProjectCollection projects, ProjectRootElement project) private MsbuildProject(ProjectCollection projects, ProjectRootElement project)
{ {
@ -168,6 +169,12 @@ namespace Microsoft.DotNet.Tools
return _cachedTfms; return _cachedTfms;
} }
public IEnumerable<string> GetConfigurations()
{
return cachedConfigurations ??
(cachedConfigurations = GetEvaluatedProject().GetConfigurations());
}
public bool CanWorkOnFramework(NuGetFramework framework) public bool CanWorkOnFramework(NuGetFramework framework)
{ {
foreach (var tfm in GetTargetFrameworks()) foreach (var tfm in GetTargetFrameworks())

View file

@ -32,6 +32,11 @@ namespace Microsoft.DotNet.Tools.ProjectExtensions
.Select((frameworkString) => NuGetFramework.Parse(frameworkString)); .Select((frameworkString) => NuGetFramework.Parse(frameworkString));
} }
public static IEnumerable<string> GetConfigurations(this Project project)
{
return project.GetPropertyCommaSeparatedValues("Configurations");
}
public static IEnumerable<string> GetPropertyCommaSeparatedValues(this Project project, string propertyName) public static IEnumerable<string> GetPropertyCommaSeparatedValues(this Project project, string propertyName)
{ {
return project.GetPropertyValue(propertyName) return project.GetPropertyValue(propertyName)

View file

@ -40,6 +40,11 @@ namespace Microsoft.DotNet.Cli
.Select(r => r.Include) ?? .Select(r => r.Include) ??
Empty<string>(); Empty<string>();
public static IEnumerable<string> ConfigurationsFromProjectFileOrDefaults() =>
GetMSBuildProject()
?.GetConfigurations() ??
new[] { "Debug", "Release" };
private static MsbuildProject GetMSBuildProject() private static MsbuildProject GetMSBuildProject()
{ {
try try
@ -55,4 +60,4 @@ namespace Microsoft.DotNet.Cli
} }
} }
} }
} }