Search code examples
asp.net-core.net-6.0asp.net-core-scaffolding

aspnet-codegenerator error: "path is empty"


I'm attempting to scaffold the Identity pages for a new .NET 6.0 project (created from the ASP.NET Core MVC template). When I run the following command I get the error "path is empty" (I also included the build command output to show the project builds successfully).

> 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

This error, "The path is empty," also appears (without the stack trace) when attempting to scaffold a new Razor view (e.g. Create) via the Add -> View context menu in Visual Studio 2022.

Is this a configuration issue, or a bug in the code generator?

Edit (2021-11-29): After reproducing this error from scratch, it appears it occurs after adding the Microsoft.AspNetCore.Identity Nuget package to the project, as shown below.

Reproduction Steps:

  1. Create a new project in Visual Studio 2022 using the template "ASP.NET Core Web App (Model-View-Controller)" targeting .NET 6.0 and with the authentication type set to Individual Accounts.

  2. Add the following Nuget package:

    • Microsoft.VisualStudio.Web.CodeGeneration.Design (to support scaffolding)
  3. Save all files (Ctrl + Shift + S) and rebuild the solution.

  4. At this point, open cmd to the project file's directory and run "dotnet aspnet-codegenerator identity -lf" to ensure the list of available Identity views for scaffolding is shown successfully.

  5. Add the following Nuget package:

    • Microsoft.AspNetCore.Identity
  6. Save all files (Ctrl + Shift + S) and rebuild the solution.

  7. Try to re-run the command "dotnet aspnet-codegenerator identity -lf" and the following error should occur:

     [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
    

Solution

  • As mentioned by the comment on the question and on this site

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

    Removing the nuget package Microsoft.AspNetCore.Identity from all projects in the relevant solution solves the problem.

    In many cases (also in mine) its enough to reference the nuget package Microsoft.AspNetCore.Identity.EntityFrameworkCore