我正在將本地登錄身份頁面搭建到已經具有默認身份的 asp.net 核心解決方案中。我這樣做是為了自定義我的登錄頁面。
我已經使用兩個測驗應用程式成功完成了此操作,這些應用程式使用相同的基本代碼并安裝了更多的軟體包),然后在我的決賽中嘗試此操作。
對于我的應用程式,當我發出以下命令時,出現此錯誤:
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
沒有關于'codegen_trace'in docs 的資訊。
我已經搜索并發現了很多對這個錯誤的參考。但找不到任何東西:
- 什么是“專案背景關系”
- 我如何使用“codegen_trace”
解決方案構建成功。
我一直非常小心地跟蹤所涉及的包裹
Microsoft.VisualStudio.Web.CodeGeneration.DesignMicrosoft.AspNetCore.Identity.EntityFrameworkCoreMicrosoft.AspNetCore.Identity.UIAzure.Identity
使用
<TargetFramework>net5.0</TargetFramework>dotnet-aspnet-codegenerator' (version '5.0.0')dotnet sdk 5.0.403Microsoft.NETCore.App 5.0.12
大多數帖子都談到回滾工具版本/包等。我想知道是否有人可以實際指出可靠的除錯策略。
我在下面的這個問題中添加資訊
使用提供的幫助 - codegen_trace 的輸出
Microsoft.Extensions.ProjectModel.MsBuildProjectContextBuilder.Build()
/_/src/Ext.ProjectModel.MsBuild.Sources/MsBuildProjectContextBuilder.cs:line 56
At Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program
.GetProjectInformation(String projectPath, String configuration) in
/_/src/dotnet-aspnet-codegenerator/Program.cs:line 290
At Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program
.BuildAndDispatchDependencyCommand(String[] args,
String projectPath, String buildBasePath, String configuration, Boolean noBuild, ILogger logger)
in /_/src/dotnet-aspnet-codegenerator/Program.cs:line 173
Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program
.<>c__DisplayClass19_0.<Execute>b__0() in
/_/src/dotnet-aspnet-codegenerator/Program.cs:line 129
從這個輸出它看起來像安裝包 Microsoft.VisualStudio.Web.CodeGeneration.Tools 5.0.2 中的一個問題
我試圖在 Visual Studio 2019(最新)中將包更新到 6.0,0,但得到以下資訊:
NU1202: Package Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.0 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.0 supports: net6.0 (.NETCoreApp,Version=v6.0)
我查看了該專案的 github 存盤庫,但找不到任何有關與 .NETCoreApp,Version=v5.0 兼容的檔案
參考原始錯誤資訊:
PM> dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext
Failed to get Project Context for C:\Users\...\rollbase.csproj
我已經將代碼生成器作業的專案的 .csproj 檔案與代碼生成器無法獲取專案背景關系的檔案進行了比較。
主要區別在于屬性組。
代碼生成器的作業原理:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-testbase1-57C4221E-46E9-4653-A734-4C412F7C523D</UserSecretsId>
</PropertyGroup>
找不到專案背景關系的地方:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-rollbase-6D7D2449-EB25-45CE-A8D3-EDAB69CDCAB3</UserSecretsId>
<RootNamespace></RootNamespace>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<AssemblyName />
<PackageId />
<EnableNETAnalyzers>false</EnableNETAnalyzers>
</PropertyGroup>
uj5u.com熱心網友回復:
請檢查您的代碼生成器 CLI 工具版本是否與您的 .NET 版本相同。codegen_trace如果您使用的是 Linux 或 mac,則需要像這樣設定環境變數
codegen_trace=1
如果您使用的是 Powershell,則可以這樣設定。
$env:codegen_trace=1
有一個與此相關的 GitHub 公開問題。請檢查解決方案。- https://github.com/dotnet/Scaffolding/issues/1388
uj5u.com熱心網友回復:
理解codegen_trace環境變數及其輸出的最好方法是閱讀源代碼。
要啟用跟蹤日志,請codegen_trace在運行之前設定環境變數dotnet-aspnet-codegenerator:
命令提示符
SET codegen_trace=1電源外殼
$env:codegen_trace=1Bash/Zsh/魚
export codegen_trace=1
該專案背景意味著專案的背景關系資訊。大多數專案資訊包含在*.csproj檔案中。您的問題很可能是您的專案無法成功構建。您必須確保您的專案是可構建的。
對于您的dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext命令,您至少需要安裝以下軟體包才能正常作業。
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
uj5u.com熱心網友回復:
我編輯了專案檔案 PropertyGroup 部分。從它是什么(見上面問題的附加資訊)到:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-rollbase-6D7D2449-EB25-45CE-A8D3-EDAB69CDCAB3</UserSecretsId>
</PropertyGroup>
身份檔案使用以下方式搭建:
dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext
[Trace]: Command Line: identity --dbContext ApplicationDbContext
Building project ...
[Trace]: Command Line: --no-dispatch --port-number 52819 identity --dbContext ApplicationDbContext --dispatcher-version 5.0.0 a93dad81ee7f820d8e33d3f91e066ef68053d004
Finding the generator 'identity'...
Running the generator 'identity'...
...etc...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/374006.html
