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,
Accept.ExactlyOneArgument()
.With(name: CommonLocalizableStrings.ConfigurationArgumentName)
.WithSuggestionsFrom("Debug", "Release")
.WithSuggestionsFrom(_ => Suggest.ConfigurationsFromProjectFileOrDefaults())
.ForwardAsSingle(o => $"-property:Configuration={o.Arguments.Single()}"));
public static Option VersionSuffixOption() =>

View file

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

View file

@ -32,6 +32,11 @@ namespace Microsoft.DotNet.Tools.ProjectExtensions
.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)
{
return project.GetPropertyValue(propertyName)

View file

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