Why can't I install Microsoft.VisualStudio.Web.CodeGeneration.Tools 2.0.1 via nuget? Asp.NET CORE 2.0.1
我已添加对我的 project.csproj 文件的引用,如 S.O. 中所示。并在 ms 文档教程中:
1 2 3 | <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" /> </ItemGroup> |
运行
这似乎来自我不了解或不知道如何解决的版本兼容性问题。我已经在我的依赖项中安装了 Microsoft.NETCore.App 2.0.3
和 Microsoft.NETCore.APP 2.0.3,其他一切都是 2.0.1。 (CodeGeneration.Design、CodeGeneration.Utils 等...并在包管理控制台
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | GET https://api.nuget.org/v3/registration3-gz-semver2/microsoft.visualstudio.web.codegeneration.tools/index.json OK https://api.nuget.org/v3/registration3-gz-semver2/microsoft.visualstudio.web.codegeneration.tools/index.json 166ms Restoring packages for C:\\Users\\sticker592\\Documents\\Visual Studio 2017\\Projects\\ContosoUniversity\\ContosoUniversity\\ContosoUniversity.csproj... Install-Package : Detected package downgrade: Microsoft.NETCore.App from 2.0.3 to 2.0.0. Reference the package directly from the project to select a different version. ContosoUniversity -> Microsoft.VisualStudio.Web.CodeGeneration.Tools 2.0.1 -> Microsoft.NETCore.App (>= 2.0.3) ContosoUniversity -> Microsoft.NETCore.App (>= 2.0.0) At line:1 char:1 + Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Tools + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand Install-Package : Package restore failed. Rolling back package changes for 'ContosoUniversity'. At line:1 char:1 + Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Tools + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand |
将所有内容降级到 2.0.0 允许我在 Nuget 中安装 CodeGeneration.Tools 但我仍然收到错误:
在 Nuget 包管理器和
中转到"管理 Nuget 包以获得解决方案"
在包源中
.
添加以下详细信息:
名称
"nuget.org"
来源
"https://api.nuget.org/v3/index.json"
如果发生这种情况,解决该错误的方法是在项目文件夹目录中的 dos 命令提示符下运行命令,而不是在包管理器控制台中。然后你可以在没有错误的情况下搭建你的页面,直到 MS 修复了这个错误。
证明:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | C:\\Users\\username\\Documents\\Visual Studio 2017\\Projects\\ContosoUniversity\\ContosoUniversity>dotnet aspnet-codegenerator razorpage -m Student -dc SchoolContext -udl -outDir Pages\\Students --referenceScriptLibraries Building project ... Finding the generator 'razorpage'... Running the generator 'razorpage'... Attempting to compile the application in memory. Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Student' info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using 'C:\\Users\\username\\AppData\\Local\\ASP.NET\\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. info: Microsoft.EntityFrameworkCore.Infrastructure[100403] Entity Framework Core 2.0.0-rtm-26452 initialized 'SchoolContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None Added Razor Page : \\Pages\\Students\\Create.cshtml Added PageModel : \\Pages\\Students\\Create.cshtml.cs Added Razor Page : \\Pages\\Students\\Edit.cshtml Added PageModel : \\Pages\\Students\\Edit.cshtml.cs Added Razor Page : \\Pages\\Students\\Details.cshtml Added PageModel : \\Pages\\Students\\Details.cshtml.cs Added Razor Page : \\Pages\\Students\\Delete.cshtml Added PageModel : \\Pages\\Students\\Delete.cshtml.cs Added Razor Page : \\Pages\\Students\\Index.cshtml Added PageModel : \\Pages\\Students\\Index.cshtml.cs RunTime 00:00:15.33 |