Skip to content

Commit 066d969

Browse files
authored
feat(codeintel): Add new command line arguments for customizing dotnet restore (#69)
1 parent dbbe7f7 commit 066d969

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

ScipDotnet/IndexCommandHandler.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ namespace ScipDotnet;
1111

1212
public static class IndexCommandHandler
1313
{
14-
public static async Task<int> Process(IHost host, List<FileInfo> projects, string output, FileInfo workingDirectory,
15-
List<string> include, List<string> exclude, bool allowGlobalSymbolDefinitions, int dotnetRestoreTimeout)
14+
public static async Task<int> Process(
15+
IHost host,
16+
List<FileInfo> projects,
17+
string output,
18+
FileInfo workingDirectory,
19+
List<string> include,
20+
List<string> exclude,
21+
bool allowGlobalSymbolDefinitions,
22+
int dotnetRestoreTimeout,
23+
bool skipDotnetRestore,
24+
FileInfo? nugetConfigPath
25+
)
1626
{
1727
var logger = host.Services.GetRequiredService<ILogger<IndexCommandOptions>>();
1828
var matcher = new Matcher();
@@ -34,7 +44,9 @@ public static async Task<int> Process(IHost host, List<FileInfo> projects, strin
3444
logger,
3545
matcher,
3646
allowGlobalSymbolDefinitions,
37-
dotnetRestoreTimeout
47+
dotnetRestoreTimeout,
48+
skipDotnetRestore,
49+
nugetConfigPath
3850
);
3951
await ScipIndex(host, options);
4052
return 0;

ScipDotnet/IndexCommandOptions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ public record IndexCommandOptions(
1010
ILogger<IndexCommandOptions> Logger,
1111
Matcher Matcher,
1212
bool AllowGlobalSymbolDefinitions,
13-
int DotnetRestoreTimeout
13+
int DotnetRestoreTimeout,
14+
bool SkipDotnetRestore,
15+
FileInfo? NugetConfigPath
1416
);

ScipDotnet/Program.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ public static async Task<int> Main(string[] args)
4242
"If enabled, allow public symbol definitions to be accessible from other SCIP indexes. " +
4343
"If disabled, then public symbols will only be visible within the index."),
4444
new Option<int>("--dotnet-restore-timeout", () => DotnetRestoreTimeout,
45-
@"The timeout (in ms) for the ""dotnet restore"" command")
45+
@"The timeout (in ms) for the ""dotnet restore"" command"),
46+
new Option<bool>("--skip-dotnet-restore", () => false,
47+
@"Skip executing ""dotnet restore"" and assume it has been run externally."),
48+
new Option<FileInfo?>("--nuget-config-path", () => null,
49+
@"Provide a case sensitive custom path for ""dotnet restore"" to find the NuGet.config file. " +
50+
@"If not provided, ""dotnet restore"" will search for the NuGet.config file recursively up the folder hierarchy " +
51+
@"and in the default user and system config locations."),
4652
};
4753
indexCommand.Handler = CommandHandler.Create(IndexCommandHandler.Process);
4854
var rootCommand =

ScipDotnet/ScipProjectIndexer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public ScipProjectIndexer(ILogger<ScipProjectIndexer> logger) =>
2121
private void Restore(IndexCommandOptions options, FileInfo project)
2222
{
2323
var arguments = project.Extension.Equals(".sln") ? $"restore {project.FullName} /p:EnableWindowsTargeting=true" : "restore /p:EnableWindowsTargeting=true";
24+
if (options.NugetConfigPath != null)
25+
{
26+
arguments += $" --configfile \"{options.NugetConfigPath.FullName}\"";
27+
}
2428
var process = new Process()
2529
{
2630
StartInfo = new ProcessStartInfo()
@@ -55,7 +59,11 @@ private void Restore(IndexCommandOptions options, FileInfo project)
5559
FileInfo rootProject,
5660
HashSet<ProjectId> indexedProjects)
5761
{
58-
Restore(options, rootProject);
62+
if (!options.SkipDotnetRestore)
63+
{
64+
Restore(options, rootProject);
65+
}
66+
5967
var projects = (string.Equals(rootProject.Extension, ".csproj") || string.Equals(rootProject.Extension, ".vbproj")
6068
? new[]
6169
{

0 commit comments

Comments
 (0)