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

Commit 3e575f7

Browse files
author
Peter Huene
committed
Prevent default item globbing when evaluating run properties.
When `dotnet run` is executed, a project evaluation occurs to obtain properties related to running the target executable. Currently, this evaluation causes the default item globs to be evaluated. For project directories containing a large number of files, this can be a bit performance hit since the globbing happens twice: once for the build and again for evaluating the run properties. This commit prevents the globbing from taking place when evaluating the run properties. Fixes #8103.
1 parent 01c1187 commit 3e575f7

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Microsoft.DotNet.Cli.Utils/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class Constants
1818

1919
public static readonly string MSBUILD_EXE_PATH = "MSBUILD_EXE_PATH";
2020
public static readonly string MSBuildExtensionsPath = "MSBuildExtensionsPath";
21+
public static readonly string EnableDefaultItems = "EnableDefaultItems";
2122

2223
public static readonly string ProjectArgumentName = "<PROJECT>";
2324
public static readonly string SolutionArgumentName = "<SLN_FILE>";

src/dotnet/commands/dotnet-run/RunCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using Microsoft.Build.Evaluation;
8+
using Microsoft.Build.Execution;
99
using Microsoft.Build.Exceptions;
1010
using Microsoft.DotNet.Cli.Utils;
1111
using Microsoft.DotNet.Tools;
@@ -184,6 +184,9 @@ private ICommand GetRunCommand()
184184
{
185185
var globalProperties = new Dictionary<string, string>
186186
{
187+
// This property disables default item globbing to improve performance
188+
// This should be safe because we are not evaluating items, only properties
189+
{ Constants.EnableDefaultItems, "false" },
187190
{ Constants.MSBuildExtensionsPath, AppContext.BaseDirectory }
188191
};
189192

@@ -197,7 +200,7 @@ private ICommand GetRunCommand()
197200
globalProperties.Add("TargetFramework", Framework);
198201
}
199202

200-
Project project = new Project(Project, globalProperties, null);
203+
var project = new ProjectInstance(Project, globalProperties, null);
201204

202205
string runProgram = project.GetPropertyValue("RunCommand");
203206
if (string.IsNullOrEmpty(runProgram))
@@ -220,7 +223,7 @@ private ICommand GetRunCommand()
220223
.WorkingDirectory(runWorkingDirectory);
221224
}
222225

223-
private void ThrowUnableToRunError(Project project)
226+
private void ThrowUnableToRunError(ProjectInstance project)
224227
{
225228
string targetFrameworks = project.GetPropertyValue("TargetFrameworks");
226229
if (!string.IsNullOrEmpty(targetFrameworks))

0 commit comments

Comments
 (0)