aspnet-codegenerator error: "path is empty"

aspnet-codegenerator error: "path is empty"

我正在尝试为一个新的 .NET 6.0 项目(从 ASP.NET 核心 MVC 模板创建)构建标识页面。当我 运行 以下命令时,我收到错误“路径为空”(我还包括构建命令输出以显示项目构建成功)。

> dotnet build

Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  ExampleProject -> C:\...\bin\Debug\net6.0\ExampleProject.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.52


> dotnet aspnet-codegenerator identity -lf

[Trace]: Command Line: identity -lf
Building project ...
[Trace]: Command Line: --no-dispatch --port-number 64193 identity -lf --dispatcher-version 6.0.0+cc9d1f5236d926269a0471042f72bf83b498509c
Scaffolding failed.
The path is empty. (Parameter 'path')
[Trace]:    at System.IO.Path.GetFullPath(String path)
   at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
   at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.ProjectContextWriter.GetScaffoldingAssemblies(IEnumerable`1 dependencies)
   at Microsoft.DotNet.Scaffolding.Shared.ProjectModel.ProjectContextExtensions.AddPackageDependencies(IProjectContext projectInformation, String projectAssetsFile)
   at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<<Execute>b__0>d.MoveNext()
RunTime 00:00:02.43

在 Visual Studio 2022 年尝试通过添加 -> 查看上下文菜单构建新的 Razor 视图(例如创建)时,也会出现此错误“路径为空”(没有堆栈跟踪) .

这是配置问题还是代码生成器中的错误?

编辑(2021-11-29): 从头开始​​重现此错误后,似乎是在将 Microsoft.AspNetCore.Identity Nuget 包添加到项目后发生的,如如下所示。

复制步骤:

  1. 在 Visual Studio 2022 年使用模板“ASP.NET Core Web App (Model-View-Controller)”以 .NET 6.0 为目标并使用身份验证类型创建一个新项目设置为个人帐户。

  2. 添加以下 Nuget 包:

    • Microsoft.VisualStudio.Web.CodeGeneration.Design(支持脚手架)
  3. 保存所有文件 (Ctrl + Shift + S) 并重建解决方案。

  4. 此时,打开项目文件目录的 cmd 和 运行“dotnet aspnet-codegenerator identity -lf”以确保成功显示可用于脚手架的身份视图列表。

  5. 添加以下 Nuget 包:

    • Microsoft.AspNetCore.Identity
  6. 保存所有文件 (Ctrl + Shift + S) 并重建解决方案。

  7. 尝试重新运行命令“dotnet aspnet-codegenerator identity -lf”应该出现以下错误:

     [Trace]: Command Line: identity -lf
     Building project ...
     [Trace]: Command Line: --no-dispatch --port-number 57313 identity -lf --dispatcher-version 6.0.0+cc9d1f5236d926269a0471042f72bf83b498509c
     Scaffolding failed.
     The path is empty. (Parameter 'path')
     [Trace]:    at System.IO.Path.GetFullPath(String path)
        at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
        at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
        at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
        at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
        at Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.ProjectContextWriter.GetScaffoldingAssemblies(IEnumerable`1 dependencies)
        at Microsoft.DotNet.Scaffolding.Shared.ProjectModel.ProjectContextExtensions.AddPackageDependencies(IProjectContext projectInformation, String projectAssetsFile)
        at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<<Execute>b__0>d.MoveNext()
     RunTime 00:00:03.53
    

如问题评论和本网站所述

https://github.com/dotnet/Scaffolding/issues/1713

从相关解决方案中的所有项目中删除nuget包Microsoft.AspNetCore.Identity解决了问题。

在很多情况下(在我的情况下)它足以引用 nuget 包 Microsoft.AspNetCore.Identity.EntityFrameworkCore