5

我正在尝试为新的 .NET 6.0 项目(从 ASP.NET Core 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.IdentityNuget 包添加到项目后发生,如下所示。

复制步骤:

  1. 使用面向 .NET 6.0 的模板“ASP.NET Core Web 应用程序(模型-视图-控制器)”并将身份验证类型设置为个人帐户,在 Visual Studio 2022 中创建一个新项目。

  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
    
4

1 回答 1

2

正如对问题和本网站的评论所述

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

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

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

于 2022-01-20T15:49:57.417 回答