dotnet / dotnet/Scaffolding

Identity scaffolding failed

Open
#3,157 0 comments 0 reactions 0 assignees View on GitHub
area-scaffolding customer-reported
Dominant language
C#
Stars
818
Forks
260
Avg merge
1d 8h
Merged PRs (30d)
10

Description

Trying to scaffold some pages for identity and getting error

```
Running command: C:\Develope\Repos\myproject\artifacts\obj\MyProject\dotnet-aspnet-codegenerator.exe --project C:\Develope\Repos\myproject\MyProject\MyProject.csproj --target-framework net9.0 --configuration "Debug" --no-build identity --dbContext MyProject.Common.Infrastructure.Identity.ApplicationDbContext --files "Account.Manage._Layout" --layout ~/Pages/Shared/_Layout.cshtml
[Trace]: Command Line: --project C:\Develope\Repos\myproject\MyProject\MyProject.csproj --target-framework net9.0 --configuration Debug --no-build identity --dbContext MyProject.Common.Infrastructure.Identity.ApplicationDbContext --files Account.Manage._Layout --layout ~/Pages/Shared/_Layout.cshtml
[Trace]: Executing external command:
dotnet msbuild C:\Develope\Repos\myproject\MyProject\MyProject.csproj /t:EvaluateProjectInfoForCodeGeneration /p:OutputFile=C:\Users\rene.spisak\AppData\Local\Temp\c1vylos0.d23;CodeGenerationTargetLocation=C:\Develope\Repos\myproject\artifacts\obj\MyProject\.store\dotnet-aspnet-codegenerator\9.0.0\dotnet-aspnet-codegenerator\9.0.0\tools\net8.0\any;Configuration=Debug -restore

Scaffolding failed.
Failed to get Project Context for C:\Develope\Repos\myproject\MyProject\MyProject.csproj.

[Trace]: at Microsoft.Extensions.ProjectModel.MsBuildProjectContextBuilder.Build() in /_/src/Shared/Microsoft.DotNet.Scaffolding.Shared/MsBuild/MsBuildProjectContextBuilder.cs:line 56
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.GetProjectInformation(String projectPath, String configuration) in /_/src/Scaffolding/dotnet-aspnet-codegenerator/Program.cs:line 289
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.BuildAndDispatchDependencyCommand(String[] args, String projectPath, String buildBasePath, String configuration, Boolean noBuild, ILogger logger) in /_/src/Scaffolding/dotnet-aspnet-codegenerator/Program.cs:line 172
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.<>c__DisplayClass19_0.b__0() in /_/src/Scaffolding/dotnet-aspnet-codegenerator/Program.cs:line 129
RunTime 00:00:10.75
Scaffolding 'Identity' has finished with errors:
* Scaffold item command has finished with error: Scaffolding failed.Failed to get Project Context for C:\Develope\Repos\myproject\MyProject\MyProject.csproj.

```

Tried to check sources and it always crashed in `GetTargetsLocation` when searching for `build`.

```
private string GetTargetsLocation()
{
const string build = "build";
var assembly = typeof(Program).GetTypeInfo().Assembly;
var path = Path.GetDirectoryName(assembly.Location);
// Crawl up from assembly location till we find 'build' directory.
do
{
if (Directory.EnumerateDirectories(path, build, SearchOption.TopDirectoryOnly).Any())
{
return path;
}

path = Path.GetDirectoryName(path);
} while (path != null);

throw new DirectoryNotFoundException(string.Format(Resources.TargetDirectoryNotFound, build));
}
```

What exactly this `build` is and when it should be? I'm using artifacts to output, but disabling this feature does nothing different.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.