Skip to content

Commit e9a61f3

Browse files
Add dotnet local tool instructions tab (#8433)
* Update wording for .NET CLI (Global) tools * Add .NET local tool installation instructions * Modified one liner approach to use server-side rendering Address #8373
1 parent e2d6b38 commit e9a61f3

2 files changed

Lines changed: 35 additions & 18 deletions

File tree

src/NuGetGallery/ViewModels/PackageManagerViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public PackageManagerViewModel(string name)
3030
public string CommandPrefix { get; set; }
3131

3232
/// <summary>
33-
/// A string that represents the command used to install a specific package.
33+
/// One or more strings that represent the command(s) used to install a specific package.
3434
/// </summary>
35-
public string InstallPackageCommand { get; set; }
35+
public string[] InstallPackageCommands { get; set; }
3636

3737
/// <summary>
3838
/// The alert message that contains clarifications about the command/scenario

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,32 @@
2828
{
2929
packageManagers = new PackageManagerViewModel[]
3030
{
31-
new PackageManagerViewModel(".NET CLI")
31+
new PackageManagerViewModel(".NET CLI (Global)")
3232
{
33-
Id = "dotnet-cli",
33+
Id = "dotnet-cli-global",
34+
CommandPrefix = "> ",
35+
InstallPackageCommands = new [] { string.Format("dotnet tool install --global {0} --version {1}", Model.Id, Model.Version) },
36+
AlertLevel = AlertLevel.Info,
37+
AlertMessage = "This package contains a <a href='https://aka.ms/global-tools'>.NET tool</a> you can call from the shell/command line.",
38+
},
39+
40+
new PackageManagerViewModel(".NET CLI (Local)")
41+
{
42+
Id = "dotnet-cli-local",
3443
CommandPrefix = "> ",
35-
InstallPackageCommand = string.Format("dotnet tool install --global {0} --version {1}", Model.Id, Model.Version),
44+
InstallPackageCommands = new []
45+
{
46+
"dotnet new tool-manifest # if you are setting up this repo",
47+
string.Format("dotnet tool install --local {0} --version {1}", Model.Id, Model.Version),
48+
},
3649
AlertLevel = AlertLevel.Info,
37-
AlertMessage = "This package contains a <a href='https://aka.ms/global-tools'>.NET Core Global Tool</a> you can call from the shell/command line.",
50+
AlertMessage = "This package contains a <a href='https://aka.ms/global-tools'>.NET tool</a> you can call from the shell/command line.",
3851
},
3952

4053
new ThirdPartyPackageManagerViewModel("Cake", "https://cakebuild.net/support/nuget")
4154
{
4255
Id = "cake-dotnet-tool",
43-
InstallPackageCommand = Model.GetCakeInstallPackageCommand(),
56+
InstallPackageCommands = new [] { Model.GetCakeInstallPackageCommand() },
4457
},
4558
};
4659
}
@@ -52,7 +65,7 @@
5265
{
5366
Id = "dotnet-cli",
5467
CommandPrefix = "> ",
55-
InstallPackageCommand = string.Format("dotnet new --install {0}::{1}", Model.Id, Model.Version),
68+
InstallPackageCommands = new [] { string.Format("dotnet new --install {0}::{1}", Model.Id, Model.Version) },
5669
AlertLevel = AlertLevel.Info,
5770
AlertMessage = "This package contains a <a href='https://aka.ms/dotnet-new'>.NET Core Template Package</a> you can call from the shell/command line.",
5871
}
@@ -66,26 +79,26 @@
6679
{
6780
Id = "package-manager",
6881
CommandPrefix = "PM> ",
69-
InstallPackageCommand = string.Format("Install-Package {0} -Version {1}", Model.Id, Model.Version)
82+
InstallPackageCommands = new [] { string.Format("Install-Package {0} -Version {1}", Model.Id, Model.Version) },
7083
},
7184

7285
new PackageManagerViewModel(".NET CLI")
7386
{
7487
Id = "dotnet-cli",
7588
CommandPrefix = "> ",
76-
InstallPackageCommand = string.Format("dotnet add package {0} --version {1}", Model.Id, Model.Version)
89+
InstallPackageCommands = new [] { string.Format("dotnet add package {0} --version {1}", Model.Id, Model.Version) },
7790
},
7891

7992
new PackageManagerViewModel("PackageReference")
8093
{
8194
Id = "package-reference",
82-
InstallPackageCommand = Model.DevelopmentDependency
95+
InstallPackageCommands = new [] { Model.DevelopmentDependency
8396
? string.Format(string.Join(Environment.NewLine,
8497
"<PackageReference Include=\"{0}\" Version=\"{1}\">",
8598
" <PrivateAssets>all</PrivateAssets>",
8699
" <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>",
87100
"</PackageReference>"), Model.Id, Model.Version)
88-
: string.Format("<PackageReference Include=\"{0}\" Version=\"{1}\" />", Model.Id, Model.Version),
101+
: string.Format("<PackageReference Include=\"{0}\" Version=\"{1}\" />", Model.Id, Model.Version) },
89102
AlertLevel = AlertLevel.Info,
90103
AlertMessage = string.Format("For projects that support <a href=\"{0}\">PackageReference</a>, copy this XML node into the project file to reference the package.",
91104
"https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files"),
@@ -96,14 +109,14 @@
96109
{
97110
Id = "paket-cli",
98111
CommandPrefix = "> ",
99-
InstallPackageCommand = string.Format("paket add {0} --version {1}", Model.Id, Model.Version),
112+
InstallPackageCommands = new [] { string.Format("paket add {0} --version {1}", Model.Id, Model.Version) },
100113
},
101114

102115
new PackageManagerViewModel("F# Interactive")
103116
{
104117
Id = "fsharp-interactive",
105118
CommandPrefix = "> ",
106-
InstallPackageCommand = string.Format("#r \"nuget: {0}, {1}\"", Model.Id, Model.Version),
119+
InstallPackageCommands = new [] { string.Format("#r \"nuget: {0}, {1}\"", Model.Id, Model.Version) },
107120
AlertLevel = AlertLevel.Info,
108121
AlertMessage = string.Format(
109122
"For F# scripts that support <a href=\"{0}\">#r syntax</a>, copy this into the source code to reference the package.",
@@ -113,7 +126,7 @@
113126
new ThirdPartyPackageManagerViewModel("Cake", "https://cakebuild.net/support/nuget")
114127
{
115128
Id = Model.IsCakeExtension() ? "cake-extension" : "cake",
116-
InstallPackageCommand = Model.GetCakeInstallPackageCommand()
129+
InstallPackageCommands = new [] { Model.GetCakeInstallPackageCommand() },
117130
},
118131
};
119132
}
@@ -165,11 +178,15 @@
165178
@helper CommandPanel(PackageManagerViewModel packageManager, bool active)
166179
{
167180
var thirdPartyPackageManager = packageManager as ThirdPartyPackageManagerViewModel;
168-
169181
<div role="tabpanel" class="tab-pane @(active ? "active" : string.Empty)" id="@packageManager.Id">
170182
<div>
171183
<div class="install-script-row">
172-
<pre class="install-script" id="@packageManager.Id-text">@packageManager.InstallPackageCommand</pre>
184+
@{
185+
var lastIndex = packageManager.InstallPackageCommands.Length - 1;
186+
var cs = packageManager.InstallPackageCommands.Select((c, i) => i < lastIndex ? c + Environment.NewLine : c);
187+
}
188+
@* Writing out the install command must be on a single line to avoid undesired whitespace in the <pre> tag. *@
189+
<pre class="install-script" id="@packageManager.Id-text">@foreach (var c in cs) {<span class="install-command-row">@c</span>}</pre>
173190
<div class="copy-button">
174191
<!--In order to statisfy the requirement to announce button status both on NVDA/Narrator, other screen reader like NVDA will
175192
announce the data-content "Copied" everytime when we press button, however, it won't work with Narrator when we use bootstrap popover
@@ -1184,7 +1201,7 @@
11841201
continue;
11851202
}
11861203

1187-
packageManagersCss += "#" + packageManager.Id + " .install-script::before {";
1204+
packageManagersCss += "#" + packageManager.Id + " .install-command-row::before {";
11881205
packageManagersCss += " content: \"" + packageManager.CommandPrefix + "\"";
11891206
packageManagersCss += "}";
11901207
}

0 commit comments

Comments
 (0)