-
Notifications
You must be signed in to change notification settings - Fork 743
Expand file tree
/
Copy pathGetProjectCommand.cs
More file actions
76 lines (66 loc) · 2.93 KB
/
GetProjectCommand.cs
File metadata and controls
76 lines (66 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable disable
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Management.Automation;
using NuGet.VisualStudio;
namespace NuGet.PackageManagement.PowerShellCmdlets
{
/// <summary>
/// This cmdlet returns the list of project names in the current solution,
/// which is also used for tab expansion.
/// </summary>
[Cmdlet(VerbsCommon.Get, "Project", DefaultParameterSetName = ParameterSetByName)]
[OutputType(typeof(EnvDTE.Project))]
public class GetProjectCommand : NuGetPowerShellBaseCommand
{
private const string ParameterSetByName = "ByName";
private const string ParameterSetAllProjects = "AllProjects";
[Parameter(Mandatory = false, Position = 0, ParameterSetName = ParameterSetByName, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "PowerShell API requirement")]
public string[] Name { get; set; }
[Parameter(Mandatory = true, ParameterSetName = ParameterSetAllProjects)]
public SwitchParameter All { get; set; }
/// <summary>
/// logging time disabled for tab command
/// </summary>
protected override bool IsLoggingTimeDisabled => true;
private void Preprocess()
{
CheckSolutionState();
NuGetUIThreadHelper.JoinableTaskFactory.Run(async () => await GetNuGetProjectAsync());
}
protected override void ProcessRecordCore()
{
Preprocess();
if (All.IsPresent)
{
VsSolutionManager.EnsureSolutionIsLoaded();
var projects = NuGetUIThreadHelper.JoinableTaskFactory.Run(
async () => (await VsSolutionManager.GetAllVsProjectAdaptersAsync()).Select(p => p.Project));
WriteObject(projects, enumerateCollection: true);
}
else
{
// No name specified; return default project (if not null)
if (Name == null)
{
var defaultProject = NuGetUIThreadHelper.JoinableTaskFactory.Run(
async () => await GetDefaultProjectAsync());
if (defaultProject != null)
{
WriteObject(defaultProject.Project);
}
}
else
{
// get all projects matching name(s) - handles wildcards
NuGetUIThreadHelper.JoinableTaskFactory.Run(
async () => WriteObject((await GetProjectsByNameAsync(Name)).Select(p => p.Project), enumerateCollection: true));
}
}
}
}
}