Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit fe89456

Browse files
author
Peter Huene
committed
Add source option to install tool command.
This commit adds the `--source` option to the `install tool` command. This option is equivalent to the option of the same name for the `restore` command. The option is forwarded to the underlying restore operation. Fixes #8226.
1 parent a212d5a commit fe89456

22 files changed

+423
-43
lines changed

src/dotnet/ToolPackage/IProjectRestorer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal interface IProjectRestorer
1010
void Restore(
1111
FilePath projectPath,
1212
DirectoryPath assetJsonOutput,
13-
FilePath? nugetconfig);
13+
FilePath? nugetconfig,
14+
string source);
1415
}
1516
}

src/dotnet/ToolPackage/ToolPackageObtainer.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public ToolConfigurationAndExecutableDirectory ObtainAndReturnExecutablePath(
3535
string packageId,
3636
string packageVersion = null,
3737
FilePath? nugetconfig = null,
38-
string targetframework = null)
38+
string targetframework = null,
39+
string source = null)
3940
{
4041
if (packageId == null)
4142
{
@@ -74,7 +75,7 @@ public ToolConfigurationAndExecutableDirectory ObtainAndReturnExecutablePath(
7475
packageId);
7576
}
7677

77-
InvokeRestore(nugetconfig: nugetconfig, tempProjectPath: tempProjectPath, individualToolVersion: toolDirectory);
78+
_projectRestorer.Restore(tempProjectPath, toolDirectory, nugetconfig, source);
7879

7980
if (packageVersionOrPlaceHolder.IsPlaceholder)
8081
{
@@ -131,14 +132,6 @@ private static ToolConfiguration GetConfiguration(
131132
return toolConfiguration;
132133
}
133134

134-
private void InvokeRestore(
135-
FilePath? nugetconfig,
136-
FilePath tempProjectPath,
137-
DirectoryPath individualToolVersion)
138-
{
139-
_projectRestorer.Restore(tempProjectPath, individualToolVersion, nugetconfig);
140-
}
141-
142135
private FilePath CreateTempProject(
143136
string packageId,
144137
PackageVersion packageVersion,
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<data name="SourceOptionDescription" xml:space="preserve">
121+
<value>Specifies a NuGet package source to use during installation.</value>
122+
</data>
123+
<data name="SourceOptionName" xml:space="preserve">
124+
<value>SOURCE</value>
125+
</data>
126+
</root>

src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommand.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class InstallToolCommand : CommandBase
2020
private static string _packageVersion;
2121
private static string _configFilePath;
2222
private static string _framework;
23+
private static string _source;
2324

2425
public InstallToolCommand(
2526
AppliedOption appliedCommand,
@@ -35,25 +36,14 @@ public InstallToolCommand(
3536
_packageVersion = appliedCommand.ValueOrDefault<string>("version");
3637
_configFilePath = appliedCommand.ValueOrDefault<string>("configfile");
3738
_framework = appliedCommand.ValueOrDefault<string>("framework");
39+
_source = appliedCommand.ValueOrDefault<string>("source");
3840
}
3941

4042
public override int Execute()
4143
{
42-
FilePath? configFile = null;
43-
44-
if (_configFilePath != null)
45-
{
46-
configFile = new FilePath(_configFilePath);
47-
}
48-
4944
var executablePackagePath = new DirectoryPath(new CliFolderPathCalculator().ExecutablePackagesPath);
5045

51-
var toolConfigurationAndExecutableDirectory = ObtainPackage(
52-
_packageId,
53-
_packageVersion,
54-
configFile,
55-
_framework,
56-
executablePackagePath);
46+
var toolConfigurationAndExecutableDirectory = ObtainPackage(executablePackagePath);
5747

5848
DirectoryPath executable = toolConfigurationAndExecutableDirectory
5949
.ExecutableDirectory
@@ -80,15 +70,16 @@ public override int Execute()
8070
return 0;
8171
}
8272

83-
private static ToolConfigurationAndExecutableDirectory ObtainPackage(
84-
string packageId,
85-
string packageVersion,
86-
FilePath? configFile,
87-
string framework,
88-
DirectoryPath executablePackagePath)
73+
private static ToolConfigurationAndExecutableDirectory ObtainPackage(DirectoryPath executablePackagePath)
8974
{
9075
try
9176
{
77+
FilePath? configFile = null;
78+
if (_configFilePath != null)
79+
{
80+
configFile = new FilePath(_configFilePath);
81+
}
82+
9283
var toolPackageObtainer =
9384
new ToolPackageObtainer(
9485
executablePackagePath,
@@ -100,10 +91,10 @@ private static ToolConfigurationAndExecutableDirectory ObtainPackage(
10091
new ProjectRestorer());
10192

10293
return toolPackageObtainer.ObtainAndReturnExecutablePath(
103-
packageId: packageId,
104-
packageVersion: packageVersion,
94+
packageId: _packageId,
95+
packageVersion: _packageVersion,
10596
nugetconfig: configFile,
106-
targetframework: framework);
97+
targetframework: _framework);
10798
}
10899
catch (PackageObtainException ex)
109100
{

src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommandParser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Linq;
45
using Microsoft.DotNet.Cli.CommandLine;
6+
using Microsoft.DotNet.Tools.Install.Tool;
7+
using LocalizableStrings = Microsoft.DotNet.Tools.Install.LocalizableStrings;
58

69
namespace Microsoft.DotNet.Cli
710
{
@@ -22,6 +25,11 @@ public static Command InstallTool()
2225
"--configfile",
2326
"NuGet configuration file",
2427
Accept.ExactlyOneArgument()),
28+
Create.Option(
29+
"--source",
30+
LocalizableStrings.SourceOptionDescription,
31+
Accept.ExactlyOneArgument()
32+
.With(name: LocalizableStrings.SourceOptionName)),
2533
Create.Option(
2634
"-f|--framework",
2735
"Target framework to publish for. The target framework has to be specified in the project file.",

src/dotnet/commands/dotnet-install/dotnet-install-tool/ProjectRestorer.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using Microsoft.DotNet.Cli;
7+
using Microsoft.DotNet.Cli.Utils;
78
using Microsoft.DotNet.ToolPackage;
89
using Microsoft.DotNet.PlatformAbstractions;
910
using Microsoft.Extensions.EnvironmentAbstractions;
@@ -15,7 +16,8 @@ internal class ProjectRestorer : IProjectRestorer
1516
public void Restore(
1617
FilePath projectPath,
1718
DirectoryPath assetJsonOutput,
18-
FilePath? nugetconfig)
19+
FilePath? nugetconfig,
20+
string source = null)
1921
{
2022
var argsToPassToRestore = new List<string>();
2123

@@ -26,6 +28,12 @@ public void Restore(
2628
argsToPassToRestore.Add(nugetconfig.Value.Value);
2729
}
2830

31+
if (source != null)
32+
{
33+
argsToPassToRestore.Add("--source");
34+
argsToPassToRestore.Add(source);
35+
}
36+
2937
argsToPassToRestore.AddRange(new List<string>
3038
{
3139
"--runtime",
@@ -34,9 +42,7 @@ public void Restore(
3442
});
3543

3644
var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
37-
.Create(
38-
"restore",
39-
argsToPassToRestore)
45+
.Create("restore", argsToPassToRestore)
4046
.CaptureStdOut()
4147
.CaptureStdErr();
4248

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
3+
<file datatype="xml" source-language="en" target-language="cs" original="../LocalizableStrings.resx">
4+
<body>
5+
<trans-unit id="SourceOptionDescription">
6+
<source>Specifies a NuGet package source to use during installation.</source>
7+
<target state="new">Specifies a NuGet package source to use during installation.</target>
8+
<note />
9+
</trans-unit>
10+
<trans-unit id="SourceOptionName">
11+
<source>SOURCE</source>
12+
<target state="new">SOURCE</target>
13+
<note />
14+
</trans-unit>
15+
</body>
16+
</file>
17+
</xliff>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
3+
<file datatype="xml" source-language="en" target-language="de" original="../LocalizableStrings.resx">
4+
<body>
5+
<trans-unit id="SourceOptionDescription">
6+
<source>Specifies a NuGet package source to use during installation.</source>
7+
<target state="new">Specifies a NuGet package source to use during installation.</target>
8+
<note />
9+
</trans-unit>
10+
<trans-unit id="SourceOptionName">
11+
<source>SOURCE</source>
12+
<target state="new">SOURCE</target>
13+
<note />
14+
</trans-unit>
15+
</body>
16+
</file>
17+
</xliff>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
3+
<file datatype="xml" source-language="en" target-language="es" original="../LocalizableStrings.resx">
4+
<body>
5+
<trans-unit id="SourceOptionDescription">
6+
<source>Specifies a NuGet package source to use during installation.</source>
7+
<target state="new">Specifies a NuGet package source to use during installation.</target>
8+
<note />
9+
</trans-unit>
10+
<trans-unit id="SourceOptionName">
11+
<source>SOURCE</source>
12+
<target state="new">SOURCE</target>
13+
<note />
14+
</trans-unit>
15+
</body>
16+
</file>
17+
</xliff>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
3+
<file datatype="xml" source-language="en" target-language="fr" original="../LocalizableStrings.resx">
4+
<body>
5+
<trans-unit id="SourceOptionDescription">
6+
<source>Specifies a NuGet package source to use during installation.</source>
7+
<target state="new">Specifies a NuGet package source to use during installation.</target>
8+
<note />
9+
</trans-unit>
10+
<trans-unit id="SourceOptionName">
11+
<source>SOURCE</source>
12+
<target state="new">SOURCE</target>
13+
<note />
14+
</trans-unit>
15+
</body>
16+
</file>
17+
</xliff>

0 commit comments

Comments
 (0)