Home > database >  Getting help on dotnet-aspnet-codegenerator debug output
Getting help on dotnet-aspnet-codegenerator debug output

Time:12-04

I am scaffolding a local login identity page in into a asp.net core solution that already has default identity. I am doing this in order to customize my login page.

I have successfully done this using two test apps which use the same base code with progressively more packages installed) before attempting this on my final.

For my app, when I issue the following command, I'm getting this error:

PM> dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext

Failed to get Project Context for C:\Users\...\rollbase.csproj.
To see more information, enable tracing by setting environment variable 'codegen_trace' = 1

There is no information about 'codegen_trace' in docs.

I have searched and found a lot of references to this error. But can't find anything for:

  • What is the 'Project Context'
  • How do I use a 'codegen_trace'

The solution builds successfully.

I have been very careful keeping track of the packages involved

  • Microsoft.VisualStudio.Web.CodeGeneration.Design
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.AspNetCore.Identity.UI
  • Azure.Identity

Using

  • <TargetFramework>net5.0</TargetFramework>
  • dotnet-aspnet-codegenerator' (version '5.0.0')
  • dotnet sdk 5.0.403
  • Microsoft.NETCore.App 5.0.12

Most posts talk of rolling back the tool version/packages etc. I was wanting to know if anyone out there can actually point to a solid debug strategy.

CodePudding user response:

Please check the version of your code generator CLI tool version is the same as with your.NET version. You need to set the codegen_trace as an Environmental variable like this if you're in Linux or mac

codegen_trace=1

If you're using Powershell you can set it like this.

$env:codegen_trace=1

There is a GitHub open issue related to this. Please check the solutions on that as well. - https://github.com/dotnet/Scaffolding/issues/1388

CodePudding user response:

The best way to understanding the codegen_trace environment variable and it's output is reading the source code.

To enable the Trace logs, set the codegen_trace environment variable before you run dotnet-aspnet-codegenerator:

  • Command Prompt

    SET codegen_trace=1
    
  • PowerShell

    $env:codegen_trace=1
    
  • Bash/Zsh/Fish

    export codegen_trace=1
    

The Project Context means the context of the project information. Most of the project information included in *.csproj file. Your problem is very possible that your project can't build successfully. You have to make sure your project is buildable.

For your dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext command, you at least need to install the following packages to get things right.

dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.AspNetCore.Identity.UI
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
  • Related