Skip to content

dotnet build --help results in project evaluation and msbuild SDK resolution #27374

Closed

Description

@shushanhf

Edit: See #27374 (comment) for investigation

Description

qiao@X64:~/work_qiao/dotnet-runtime-loongarch/.dotnet$ ./dotnet --info
.NET SDK (反映任何 global.json):
 Version:   6.0.108
 Commit:    4e3a463d2b

运行时环境:
 OS Name:     debian
 OS Version:  10
 OS Platform: Linux
 RID:         debian.10-x64
 Base Path:   /home/qiao/work_qiao/dotnet-runtime-loongarch/.dotnet/sdk/6.0.108/

global.json file:
  /home/qiao/work_qiao/dotnet-runtime-loongarch/global.json

Host:
  Version:      6.0.8
  Architecture: x64
  Commit:       55fb7ef977

.NET SDKs installed:
  6.0.108 [/home/qiao/work_qiao/dotnet-runtime-loongarch/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.8 [/home/qiao/work_qiao/dotnet-runtime-loongarch/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.8 [/home/qiao/work_qiao/dotnet-runtime-loongarch/.dotnet/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info


----------------------------------


qiao@X64:~/work_qiao/dotnet-runtime-loongarch/.dotnet$  time ./dotnet build --help
Description:
  .NET 生成器

Usage:
  dotnet [options] build [<PROJECT | SOLUTION>...]

Arguments:
  <PROJECT | SOLUTION>  要操作的项目或解决方案文件。如果没有指定文件,则命令将在当前目录里搜索一个文件。

Options:
  --use-current-runtime                将当前运行时用作目标运行时。
  -f, --framework <FRAMEWORK>          要生成的目标框架。必须在项目文件中指定目标框架。
  -c, --configuration <CONFIGURATION>  用于生成项目的配置。大多数项目的默认值是 "Debug"。
  -r, --runtime <RUNTIME_IDENTIFIER>   要生成的目标运行时。
  --version-suffix <VERSION_SUFFIX>    设置生成项目时使用的 $(VersionSuffix) 属性的值。
  --no-restore                         生成前请勿还原项目。
  --interactive                        允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。
  -v, --verbosity <LEVEL>              设置 MSBuild 详细程度。允许值为 q[uiet]、m[inimal]、n[ormal]、d[etailed] 和 diag[nostic]。
  --debug
  -o, --output <OUTPUT_DIR>            要放置生成项目的输出目录。
  --no-incremental                     请勿使用增量生成。
  --no-dependencies                    请勿生成项目到项目引用,仅生成指定项目。
  --nologo                             不显示启动版权标志或版权消息。
  --sc, --self-contained               随应用程序一起发布 .NET 运行时,这样就不需要在目标计算机上安装运行时。
                                       如果指定了运行时标识符,则默认值为 "true"。
  --no-self-contained                  将应用程序发布为依赖框架的应用程序。目标计算机上必须安装兼容的 .NET 运行时才能运行该应用程序。
  -a, --arch <arch>                    目标体系结构。
  --os <os>                            目标操作系统。
  -?, -h, --help                       显示命令行帮助。



real	0m0.520s
user	0m0.413s
sys	0m0.028s

while the .NET7 is slower,

qiao@X64:~/work_qiao/runtime$ .dotnet/dotnet --info
.NET SDK (反映任何 global.json):
 Version:   7.0.100-preview.7.22377.5
 Commit:    ba310d9309

运行时环境:
 OS Name:     debian
 OS Version:  10
 OS Platform: Linux
 RID:         debian.10-x64
 Base Path:   /home/qiao/work_qiao/runtime/.dotnet/sdk/7.0.100-preview.7.22377.5/

Host:
  Version:      7.0.0-preview.7.22375.6
  Architecture: x64
  Commit:       eecb028078

.NET SDKs installed:
  7.0.100-preview.7.22377.5 [/home/qiao/work_qiao/runtime/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.0-preview.7.22376.6 [/home/qiao/work_qiao/runtime/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.0-preview.7.22375.6 [/home/qiao/work_qiao/runtime/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  /home/qiao/work_qiao/runtime/global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download


-----------------------------------------

qiao@X64:~/work_qiao/runtime$ time .dotnet/dotnet build --help
Description:
  .NET 生成器

Usage:
  dotnet build [<PROJECT | SOLUTION>...] [options]

Arguments:
  <PROJECT | SOLUTION>  要操作的项目或解决方案文件。如果没有指定文件,则命令将在当前目录里搜索一个文件。

Options:
  --use-current-runtime                将当前运行时用作目标运行时。
  -f, --framework <FRAMEWORK>          要生成的目标框架。必须在项目文件中指定目标框架。
  -c, --configuration <CONFIGURATION>  用于生成项目的配置。大多数项目的默认值是 "Debug"。
  -r, --runtime <RUNTIME_IDENTIFIER>   要生成的目标运行时。
  --version-suffix <VERSION_SUFFIX>    设置生成项目时使用的 $(VersionSuffix) 属性的值。
  --no-restore                         生成前请勿还原项目。
  --interactive                        允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。
  -v, --verbosity <LEVEL>              设置 MSBuild 详细程度。允许值为 q[uiet]、m[inimal]、n[ormal]、d[etailed] 和 diag[nostic]。
  --debug
  -o, --output <OUTPUT_DIR>            要放置生成项目的输出目录。
  --no-incremental                     请勿使用增量生成。
  --no-dependencies                    请勿生成项目到项目引用,仅生成指定项目。
  --nologo                             不显示启动版权标志或版权消息。
  --sc, --self-contained               随应用程序一起发布 .NET 运行时,这样就不需要在目标计算机上安装运行时。
                                       如果指定了运行时标识符,则默认值为 "true"。
  --no-self-contained                  将应用程序发布为依赖框架的应用程序。目标计算机上必须安装兼容的 .NET 运行时才能运行该应用程序。
  -a, --arch <arch>                    目标体系结构。
  --os <os>                            目标操作系统。
  --disable-build-servers              Force the command to ignore any persistent build servers.
  -?, -h, --help                       显示命令行帮助。




real	1m15.714s
user	1m11.285s
sys	0m7.549s

Activity

  1. ghost added
    untriaged
    on Aug 19, 2022
  2. shushanhf commented on Aug 19, 2022

    @shushanhf
    Author

    There is a very insteresting thing:

    If entered the .dotnet directory, it will be very fast.

    qiao@X64:~/work_qiao/runtime/.dotnet$ time ./dotnet build --help
    Description:
      .NET 生成器
    
    Usage:
      dotnet build [<PROJECT | SOLUTION>...] [options]
    
    Arguments:
      <PROJECT | SOLUTION>  要操作的项目或解决方案文件。如果没有指定文件,则命令将在当前目录里搜索一个文件。
    
    Options:
      --use-current-runtime                将当前运行时用作目标运行时。
      -f, --framework <FRAMEWORK>          要生成的目标框架。必须在项目文件中指定目标框架。
      -c, --configuration <CONFIGURATION>  用于生成项目的配置。大多数项目的默认值是 "Debug"。
      -r, --runtime <RUNTIME_IDENTIFIER>   要生成的目标运行时。
      --version-suffix <VERSION_SUFFIX>    设置生成项目时使用的 $(VersionSuffix) 属性的值。
      --no-restore                         生成前请勿还原项目。
      --interactive                        允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。
      -v, --verbosity <LEVEL>              设置 MSBuild 详细程度。允许值为 q[uiet]、m[inimal]、n[ormal]、d[etailed] 和 diag[nostic]。
      --debug
      -o, --output <OUTPUT_DIR>            要放置生成项目的输出目录。
      --no-incremental                     请勿使用增量生成。
      --no-dependencies                    请勿生成项目到项目引用,仅生成指定项目。
      --nologo                             不显示启动版权标志或版权消息。
      --sc, --self-contained               随应用程序一起发布 .NET 运行时,这样就不需要在目标计算机上安装运行时。
                                           如果指定了运行时标识符,则默认值为 "true"。
      --no-self-contained                  将应用程序发布为依赖框架的应用程序。目标计算机上必须安装兼容的 .NET 运行时才能运行该应用程序。
      -a, --arch <arch>                    目标体系结构。
      --os <os>                            目标操作系统。
      --disable-build-servers              Force the command to ignore any persistent build servers.
      -?, -h, --help                       显示命令行帮助。
    
    
    real	0m0.261s
    user	0m0.223s
    sys	0m0.053s

    While if outside of the .dotnet directory, it will be very slow.

    qiao@X64:~/work_qiao/runtime$ time .dotnet/dotnet build --help
    Description:
      .NET 生成器
    
    Usage:
      dotnet build [<PROJECT | SOLUTION>...] [options]
    
    Arguments:
      <PROJECT | SOLUTION>  要操作的项目或解决方案文件。如果没有指定文件,则命令将在当前目录里搜索一个文件。
    
    Options:
      --use-current-runtime                将当前运行时用作目标运行时。
      -f, --framework <FRAMEWORK>          要生成的目标框架。必须在项目文件中指定目标框架。
      -c, --configuration <CONFIGURATION>  用于生成项目的配置。大多数项目的默认值是 "Debug"。
      -r, --runtime <RUNTIME_IDENTIFIER>   要生成的目标运行时。
      --version-suffix <VERSION_SUFFIX>    设置生成项目时使用的 $(VersionSuffix) 属性的值。
      --no-restore                         生成前请勿还原项目。
      --interactive                        允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。
      -v, --verbosity <LEVEL>              设置 MSBuild 详细程度。允许值为 q[uiet]、m[inimal]、n[ormal]、d[etailed] 和 diag[nostic]。
      --debug
      -o, --output <OUTPUT_DIR>            要放置生成项目的输出目录。
      --no-incremental                     请勿使用增量生成。
      --no-dependencies                    请勿生成项目到项目引用,仅生成指定项目。
      --nologo                             不显示启动版权标志或版权消息。
      --sc, --self-contained               随应用程序一起发布 .NET 运行时,这样就不需要在目标计算机上安装运行时。
                                           如果指定了运行时标识符,则默认值为 "true"。
      --no-self-contained                  将应用程序发布为依赖框架的应用程序。目标计算机上必须安装兼容的 .NET 运行时才能运行该应用程序。
      -a, --arch <arch>                    目标体系结构。
      --os <os>                            目标操作系统。
      --disable-build-servers              Force the command to ignore any persistent build servers.
      -?, -h, --help                       显示命令行帮助。
    
    
    
    
    real	1m7.394s
    user	1m3.817s
    sys	0m7.146s
  3. shushanhf commented on Aug 19, 2022

    @shushanhf
    Author

    There is a very insteresting thing:

    If entered the .dotnet directory, it will be very fast.

    qiao@X64:~/work_qiao/runtime/.dotnet$ time ./dotnet build --help
    Description:
      .NET 生成器
    
    Usage:
      dotnet build [<PROJECT | SOLUTION>...] [options]
    
    Arguments:
      <PROJECT | SOLUTION>  要操作的项目或解决方案文件。如果没有指定文件,则命令将在当前目录里搜索一个文件。
    
    Options:
      --use-current-runtime                将当前运行时用作目标运行时。
      -f, --framework <FRAMEWORK>          要生成的目标框架。必须在项目文件中指定目标框架。
      -c, --configuration <CONFIGURATION>  用于生成项目的配置。大多数项目的默认值是 "Debug"。
      -r, --runtime <RUNTIME_IDENTIFIER>   要生成的目标运行时。
      --version-suffix <VERSION_SUFFIX>    设置生成项目时使用的 $(VersionSuffix) 属性的值。
      --no-restore                         生成前请勿还原项目。
      --interactive                        允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。
      -v, --verbosity <LEVEL>              设置 MSBuild 详细程度。允许值为 q[uiet]、m[inimal]、n[ormal]、d[etailed] 和 diag[nostic]。
      --debug
      -o, --output <OUTPUT_DIR>            要放置生成项目的输出目录。
      --no-incremental                     请勿使用增量生成。
      --no-dependencies                    请勿生成项目到项目引用,仅生成指定项目。
      --nologo                             不显示启动版权标志或版权消息。
      --sc, --self-contained               随应用程序一起发布 .NET 运行时,这样就不需要在目标计算机上安装运行时。
                                           如果指定了运行时标识符,则默认值为 "true"。
      --no-self-contained                  将应用程序发布为依赖框架的应用程序。目标计算机上必须安装兼容的 .NET 运行时才能运行该应用程序。
      -a, --arch <arch>                    目标体系结构。
      --os <os>                            目标操作系统。
      --disable-build-servers              Force the command to ignore any persistent build servers.
      -?, -h, --help                       显示命令行帮助。
    
    
    real	0m0.261s
    user	0m0.223s
    sys	0m0.053s

    While if outside of the .dotnet directory, it will be very slow.

    qiao@X64:~/work_qiao/runtime$ time .dotnet/dotnet build --help
    Description:
      .NET 生成器
    
    Usage:
      dotnet build [<PROJECT | SOLUTION>...] [options]
    
    Arguments:
      <PROJECT | SOLUTION>  要操作的项目或解决方案文件。如果没有指定文件,则命令将在当前目录里搜索一个文件。
    
    Options:
      --use-current-runtime                将当前运行时用作目标运行时。
      -f, --framework <FRAMEWORK>          要生成的目标框架。必须在项目文件中指定目标框架。
      -c, --configuration <CONFIGURATION>  用于生成项目的配置。大多数项目的默认值是 "Debug"。
      -r, --runtime <RUNTIME_IDENTIFIER>   要生成的目标运行时。
      --version-suffix <VERSION_SUFFIX>    设置生成项目时使用的 $(VersionSuffix) 属性的值。
      --no-restore                         生成前请勿还原项目。
      --interactive                        允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。
      -v, --verbosity <LEVEL>              设置 MSBuild 详细程度。允许值为 q[uiet]、m[inimal]、n[ormal]、d[etailed] 和 diag[nostic]。
      --debug
      -o, --output <OUTPUT_DIR>            要放置生成项目的输出目录。
      --no-incremental                     请勿使用增量生成。
      --no-dependencies                    请勿生成项目到项目引用,仅生成指定项目。
      --nologo                             不显示启动版权标志或版权消息。
      --sc, --self-contained               随应用程序一起发布 .NET 运行时,这样就不需要在目标计算机上安装运行时。
                                           如果指定了运行时标识符,则默认值为 "true"。
      --no-self-contained                  将应用程序发布为依赖框架的应用程序。目标计算机上必须安装兼容的 .NET 运行时才能运行该应用程序。
      -a, --arch <arch>                    目标体系结构。
      --os <os>                            目标操作系统。
      --disable-build-servers              Force the command to ignore any persistent build servers.
      -?, -h, --help                       显示命令行帮助。
    
    
    
    
    real	1m7.394s
    user	1m3.817s
    sys	0m7.146s

    This only happens within the runtime directory while includes the global.json.
    If deleting the global.json, it will be normal.

  4. elinor-fung commented on Aug 19, 2022

    @elinor-fung
    Member

    @shushanhf do you see the same slower execution with commands like dotnet --info (or dotnet --help or dotnet new --help) or is it only dotnet build --help? From the runtime host side, we look at the global.json the same way in all those cases, so I'm wondering if there's something with the SDK command handling itself.

    Could you also share the contents of your global.json?

    I don't think we ended up changing how we handle global.json in .NET 7 (although there were definitely discussions about improvements). We did disable multi-level lookup, but that was Windows-only behaviour to begin with.

  5. shushanhf commented on Aug 20, 2022

    @shushanhf
    Author

    Could you also share the contents of your global.json?

    This file is within the runtime, and both runtime6.0 and runtime7.0 have this interesting thing.

    @shushanhf do you see the same slower execution with commands like dotnet --info (or dotnet --help or dotnet new --help) or is it only dotnet build --help?

    The dotnet --help and dotnet new --help are normal, the dotnet build --help and dotnet run --help had this interesting thing.

    From the runtime host side, we look at the global.json the same way in all those cases, so I'm wondering if there's something with the SDK command handling itself.

    #27374

    You must be under the root directory of the runtime project and you had downloaded the SDK, and then run the command time .dotnet/dotnet build --help.
    If you changed the directory, for example cd .. which changed to the parent directory, the command time ./runtime/.dotnet/dotnet build --help is very fast.

  6. elinor-fung commented on Aug 23, 2022

    @elinor-fung
    Member

    Ah, I missed that you were seeing this in both .NET 6 and 7.

    The dotnet --help and dotnet new --help are normal, the dotnet build --help and dotnet run --help had this interesting thing.

    That definitely makes me think there is something with the SDK command handling itself.

    Could you try setting the environment variables:

    DOTNET_CLI_PERF_LOG=1
    DOTNET_PERFLOG_DIR=<path_to_directory_for_logs>
    

    @marcpopMSFT @baronfel Is there a better/recommended way and instructions for collecting information for SDK command perf?

    I tried to make a simple repro, but did not observe this behaviour. This is my understanding of the scenario - please let me know if I have something wrong.

    Created a directory with this layout:

    .dotnet/
      dotnet
      [layout of a downloaded .NET SDK]
    global.json
    

    Where the .NET SDK is a downloaded/unzipped .NET 7 Preview 7 and global.json is copied from https://github.com/dotnet/runtime/blob/main/global.json

    • Running from within the .dotnet directory
      • These are all normal:
        dotnet --info
        dotnet --help
        dotnet new --help
        dotnet build --help
        dotnet run --help
        
    • Running from the same directory as global.json/.dotnet
      • These are normal:
        dotnet --info
        dotnet --help
        dotnet new --help
        
      • But these are considerably slower
        dotnet build --help
        dotnet run --help
        
      • If you remove global.json and run from the same directory, they are all normal.
  7. elinor-fung commented on Aug 23, 2022

    @elinor-fung
    Member

    Okay - I stopped trying to create a stripped down repro. I am able to repro this using a full clone of the runtime repo. Looks like it needs to be a combination of the msbuild-sdks specified in the global.json and other files in the repo.

  8. elinor-fung commented on Aug 23, 2022

    @elinor-fung
    Member

    This is due to some SDK commands doing a project evaluation - including resolving msbuild SDKs based on a global.json - just to print their help. When the command was run from the .dotnet directory, there is no project in the working directory to evaluate, so it was fine.

    It is triggered by the command completion for the framework option:

    public static CompletionDelegate TargetFrameworksFromProjectFile =>
    (_context) =>
    {
    try
    {
    return GetMSBuildProject()?.GetTargetFrameworks().Select(tf => tf.GetShortFolderName()).Select(ToCompletionItem) ?? Empty<CompletionItem>();
    }
    catch (Exception)
    {
    return Empty<CompletionItem>();
    }
    };

    Running --help for any command using that would hit this issue, including:

    dotnet build
    dotnet clean
    dotnet publish
    dotnet run
    dotnet store
    dotnet test
    dotnet add reference
    

    Call stack:

    > Microsoft.Build.NuGetSdkResolver.dll!Microsoft.Build.NuGetSdkResolver.NuGetSdkResolver.Resolve(Microsoft.Build.Framework.SdkReference sdkReference, Microsoft.Build.Framework.SdkResolverContext resolverContext, Microsoft.Build.Framework.SdkResultFactory factory)
      Microsoft.Build.dll!Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(System.Collections.Generic.IList<Microsoft.Build.Framework.SdkResolver> resolvers, int submissionId, Microsoft.Build.Framework.SdkReference sdk, Microsoft.Build.BackEnd.Logging.LoggingContext loggingContext, Microsoft.Build.Construction.ElementLocation sdkReferenceLocation, string solutionPath, string projectPath, bool interactive, bool isRunningInVisualStudio, out Microsoft.Build.BackEnd.SdkResolution.SdkResult sdkResult)
      Microsoft.Build.dll!Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdkUsingResolversWithPatternsFirst(int submissionId, Microsoft.Build.Framework.SdkReference sdk, Microsoft.Build.BackEnd.Logging.LoggingContext loggingContext, Microsoft.Build.Construction.ElementLocation sdkReferenceLocation, string solutionPath, string projectPath, bool interactive, bool isRunningInVisualStudio)
      Microsoft.Build.dll!Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(int submissionId, Microsoft.Build.Framework.SdkReference sdk, Microsoft.Build.BackEnd.Logging.LoggingContext loggingContext, Microsoft.Build.Construction.ElementLocation sdkReferenceLocation, string solutionPath, string projectPath, bool interactive, bool isRunningInVisualStudio)
      Microsoft.Build.dll!Microsoft.Build.BackEnd.SdkResolution.CachingSdkResolverService.ResolveSdk.AnonymousMethod__2()
      System.Private.CoreLib.dll!System.Lazy<Microsoft.Build.BackEnd.SdkResolution.SdkResult>.ViaFactory(System.Threading.LazyThreadSafetyMode mode)
      System.Private.CoreLib.dll!System.Lazy<Microsoft.Build.BackEnd.SdkResolution.SdkResult>.ExecutionAndPublication(System.LazyHelper executionAndPublication, bool useDefaultConstructor)
      System.Private.CoreLib.dll!System.Lazy<Microsoft.Build.BackEnd.SdkResolution.SdkResult>.CreateValue()
      Microsoft.Build.dll!Microsoft.Build.BackEnd.SdkResolution.CachingSdkResolverService.ResolveSdk(int submissionId, Microsoft.Build.Framework.SdkReference sdk, Microsoft.Build.BackEnd.Logging.LoggingContext loggingContext, Microsoft.Build.Construction.ElementLocation sdkReferenceLocation, string solutionPath, string projectPath, bool interactive, bool isRunningInVisualStudio)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Evaluator<Microsoft.Build.Evaluation.ProjectProperty, Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectMetadata, Microsoft.Build.Evaluation.ProjectItemDefinition>.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(string directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, out System.Collections.Generic.List<Microsoft.Build.Construction.ProjectRootElement> projects, out Microsoft.Build.BackEnd.SdkResolution.SdkResult sdkResult, bool throwOnFileNotExistsError)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Evaluator<Microsoft.Build.Evaluation.ProjectProperty, Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectMetadata, Microsoft.Build.Evaluation.ProjectItemDefinition>.ExpandAndLoadImports(string directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, out Microsoft.Build.BackEnd.SdkResolution.SdkResult sdkResult)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Evaluator<Microsoft.Build.Evaluation.ProjectProperty, Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectMetadata, Microsoft.Build.Evaluation.ProjectItemDefinition>.EvaluateImportElement(string directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Evaluator<Microsoft.Build.Evaluation.ProjectProperty, Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectMetadata, Microsoft.Build.Evaluation.ProjectItemDefinition>.PerformDepthFirstPass(Microsoft.Build.Construction.ProjectRootElement currentProjectOrImport)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Evaluator<Microsoft.Build.Evaluation.ProjectProperty, Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectMetadata, Microsoft.Build.Evaluation.ProjectItemDefinition>.Evaluate()
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Evaluator<Microsoft.Build.Evaluation.ProjectProperty, Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectMetadata, Microsoft.Build.Evaluation.ProjectItemDefinition>.Evaluate(Microsoft.Build.Evaluation.IEvaluatorData<Microsoft.Build.Evaluation.ProjectProperty, Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectMetadata, Microsoft.Build.Evaluation.ProjectItemDefinition> data, Microsoft.Build.Evaluation.Project project, Microsoft.Build.Construction.ProjectRootElement root, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, int maxNodeCount, Microsoft.Build.Collections.PropertyDictionary<Microsoft.Build.Execution.ProjectPropertyInstance> environmentProperties, Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Evaluation.IItemFactory<Microsoft.Build.Evaluation.ProjectItem, Microsoft.Build.Evaluation.ProjectItem> itemFactory, Microsoft.Build.Evaluation.IToolsetProvider toolsetP
    rovider, Microsoft.Build.Evaluation.ProjectRootElementCacheBase projectRootElementCache, Microsoft.Build.Framework.BuildEventContext buildEventContext, Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService sdkResolverService, int submissionId, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext, bool interactive)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(System.Collections.Generic.IDictionary<string, string> globalProperties, string toolsVersion, string subToolsetVersion, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.Project.Project(string projectFile, System.Collections.Generic.IDictionary<string, string> globalProperties, string toolsVersion, string subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext, Microsoft.Build.FileSystem.IDirectoryCacheFactory directoryCacheFactory)
      Microsoft.Build.dll!Microsoft.Build.Evaluation.ProjectCollection.LoadProject(string fileName, System.Collections.Generic.IDictionary<string, string> globalProperties, string toolsVersion)
      dotnet.dll!Microsoft.DotNet.Tools.MsbuildProject.GetEvaluatedProject()
      dotnet.dll!Microsoft.DotNet.Tools.MsbuildProject.GetTargetFrameworks()
      dotnet.dll!Microsoft.DotNet.Cli.Complete.get_TargetFrameworksFromProjectFile.AnonymousMethod__2_0(System.CommandLine.Completions.CompletionContext _context)
      System.Linq.dll!System.Linq.Enumerable.SelectManySingleSelectorIterator<System.CommandLine.Completions.ICompletionSource, System.CommandLine.Completions.CompletionItem>.MoveNext()
      System.Private.CoreLib.dll!System.Collections.Generic.HashSet<System.CommandLine.Completions.CompletionItem>.UnionWith(System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> other)
      System.Private.CoreLib.dll!System.Collections.Generic.HashSet<System.CommandLine.Completions.CompletionItem>.HashSet(System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> collection, System.Collections.Generic.IEqualityComparer<System.CommandLine.Completions.CompletionItem> comparer)
      System.Linq.dll!System.Linq.Enumerable.DistinctIterator<System.CommandLine.Completions.CompletionItem>.ToArray()
      System.Linq.dll!System.Linq.Buffer<System.CommandLine.Completions.CompletionItem>.Buffer(System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> source)
      System.Linq.dll!System.Linq.OrderedEnumerable<System.CommandLine.Completions.CompletionItem>.GetEnumerator()
      System.Linq.dll!System.Linq.Enumerable.SelectIPartitionIterator<System.CommandLine.Completions.CompletionItem, string>.LazyToArray()
      System.Linq.dll!System.Linq.Enumerable.SelectIPartitionIterator<System.CommandLine.Completions.CompletionItem, string>.ToArray()
      System.CommandLine.dll!System.CommandLine.Help.HelpBuilder.Default.GetArgumentUsageLabel(System.CommandLine.Argument argument)
      System.CommandLine.dll!System.CommandLine.Help.HelpBuilder.Default.GetIdentifierSymbolUsageLabel(System.CommandLine.IdentifierSymbol symbol, System.CommandLine.Help.HelpContext context)
      System.CommandLine.dll!System.CommandLine.Help.HelpBuilder.GetTwoColumnRow.__GetIdentifierSymbolRow|0()
      System.CommandLine.dll!System.CommandLine.Help.HelpBuilder.GetTwoColumnRow(System.CommandLine.Symbol symbol, System.CommandLine.Help.HelpContext context)
      System.CommandLine.dll!System.CommandLine.Help.HelpBuilder.Default.OptionsSection.AnonymousMethod__10_0(System.CommandLine.Help.HelpContext ctx)
      System.CommandLine.dll!System.CommandLine.Help.HelpBuilder.Write(System.CommandLine.Help.HelpContext context)
      System.CommandLine.dll!System.CommandLine.Invocation.InvocationPipeline.GetExitCode(System.CommandLine.Invocation.InvocationContext context)
      System.CommandLine.dll!System.CommandLine.Invocation.InvocationPipeline.Invoke.__FullInvocationChain|3_0(System.CommandLine.Invocation.InvocationContext context)
      dotnet.dll!Microsoft.DotNet.Cli.Program.ProcessArgs(string[] args, System.TimeSpan startupTime, Microsoft.DotNet.Cli.Telemetry.ITelemetry telemetryClient)
      dotnet.dll!Microsoft.DotNet.Cli.Program.Main(string[] args)
    

    Moving to dotnet/sdk

  9. transferred this issue fromdotnet/runtimeon Aug 23, 2022
  10. changed the title [-]`dotnet build --help` is slower than .NET6[/-] [+]`dotnet build --help` results in project evaluation and msbuild SDK resolution[/+] on Aug 23, 2022
  11. KalleOlaviNiemitalo commented on Oct 11, 2022

    @KalleOlaviNiemitalo
    Contributor

    .NET SDK sets ArgumentHelpName = "FRAMEWORK", which prevents --help from displaying the completions:

    public static Option<string> FrameworkOption(string description) =>
    new ForwardedOption<string>(
    new string[] { "-f", "--framework" },
    description)
    {
    ArgumentHelpName = CommonLocalizableStrings.FrameworkArgumentName
    }.ForwardAsSingle(o => $"-property:TargetFramework={o}")
    .AddCompletions(Complete.TargetFrameworksFromProjectFile);

    <data name="FrameworkArgumentName" xml:space="preserve">
    <value>FRAMEWORK</value>
    </data>

    HelpBuilder.Default.GetArgumentUsageLabel wastes time by querying the completions even though it will ignore them in this case. That could be fixed in dotnet/command-line-api, by moving the var completions initialization to an else branch:

    https://github.com/dotnet/command-line-api/blob/209b724a3c843253d3071e8348c353b297b0b8b5/src/System.CommandLine/Help/HelpBuilder.Default.cs#L66-L87

    This scenario was not optimized in dotnet/command-line-api#1367 when HelpBuilder was changed to display Argument.HelpName. Filed as dotnet/command-line-api#2038.

  12. KalleOlaviNiemitalo commented on Sep 2, 2023

    @KalleOlaviNiemitalo
    Contributor

    This has been fixed in .NET SDK 8.0.100-preview.7.23376.3. When I run dotnet build --help in a project directory, Process Monitor does not show access to any paths that contain "Microsoft.NET.Sdk". In contrast, when I run just dotnet build, Process Monitor shows access to those paths.

    I think the fix came in as part of #33157, which was merged between v8.0.100-preview.6.23330.7 and v8.0.100-preview.7.23376.5. That PR upgraded System.CommandLine from 2.0.0-beta4.22564.1 (commit 8374d5fca634a93458c84414b1604c12f765d1ab) to 2.0.0-beta4.23307.1 (commit 02fe27cd6a9b001c8feb7938e6ef4b3799745759). The diff between those includes dotnet/command-line-api#2073, which fixed dotnet/command-line-api#2038.

    Please close, unless the team intends to backport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-CLIperformanceuntriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions