我确实在论坛上进行了搜索,并检查Microsoft.AspNetCore.Blazor.Cli 0.7.0上是否存在错误NU1202。
我正在尝试使用dotnet CLI使用Blazor创建一个简单的项目。
在运行dotnet new
之前,我运行dotnet new -i来安装Blazor模板。
>dotnet new -i Microsoft.AspNetCore.Blazor.Templates
Restoring packages for C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\restore.csproj...
Installing Microsoft.AspNetCore.Blazor.Templates 0.7.0.
Generating MSBuild file C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\obj\restore.csproj.nuget.g.props.
Generating MSBuild file C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\obj\restore.csproj.nuget.g.targets.
Restore completed in 3.64 sec for C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\restore.csproj.
Restoring packages for C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\restore.csproj...
Installing Microsoft.AspNetCore.Blazor.Templates 0.7.0.
Generating MSBuild file C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\obj\restore.csproj.nuget.g.props.
Generating MSBuild file C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\obj\restore.csproj.nuget.g.targets.
Restore completed in 873.93 ms for C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.202\scratch\restore.csproj.
Templates Short Name Language Tags
---------------------------------------------------------------------------------------------------------------
Console Application console [C#], F#, VB Common/Console
Class library classlib [C#], F#, VB Common/Library
Unit Test Project mstest [C#], F#, VB Test/MSTest
xUnit Test Project xunit [C#], F#, VB Test/xUnit
Blazor (hosted in ASP.NET server) blazorhosted [C#] Web/Blazor/Hosted
Blazor Library blazorlib [C#] Web/Blazor/Library
Blazor (Server-side in ASP.NET Core) blazorserverside [C#] Web/Blazor/ServerSide
Blazor (standalone) blazor [C#] Web/Blazor/Standalone
ASP.NET Core Empty web [C#], F# Web/Empty
ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC
ASP.NET Core Web App razor [C#] Web/MVC/Razor Pages
ASP.NET Core with Angular angular [C#] Web/MVC/SPA
ASP.NET Core with React.js react [C#] Web/MVC/SPA
ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
ASP.NET Core Web API webapi [C#], F# Web/WebAPI
global.json file globaljson Config
NuGet Config nugetconfig Config
Web Config webconfig Config
Solution File sln Solution
Razor Page page Web/ASP.NET
MVC ViewImports viewimports Web/ASP.NET
MVC ViewStart viewstart Web/ASP.NET
Examples:
dotnet new mvc --auth Individual
dotnet new nugetconfig
dotnet new --help
然后开始创建一个新项目:
>dotnet new blazor -o TestBlazorApp
The template "Blazor (standalone)" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on TestBlazorApp\TestBlazorApp.csproj...
Restoring packages for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj...
Generating MSBuild file C:\<PathToProject>\TestBlazorApp\obj\TestBlazorApp.csproj.nuget.g.props.
Generating MSBuild file C:\<PathToProject>\TestBlazorApp\obj\TestBlazorApp.csproj.nuget.g.targets.
Restore completed in 1.27 sec for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj.
Restoring packages for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj...
C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj : error NU1202: Package Microsoft.AspNetCore.Blazor.Cli 0.7.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package Microsoft.AspNetCore.Blazor.Cli 0.7.0 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1)
Restore failed in 108.64 ms for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj.
Restore failed.
Post action failed.
Description: Restore NuGet packages required by this project.
Manual instructions: Run 'dotnet restore'
由于尝试运行dotnet restore
的错误
C:\Blazor Quick Start Guide\Practice\Chapter01>cd TestBlazorApp
C:\<PathToProject>\TestBlazorApp>dotnet restore
Restore completed in 49.71 ms for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj.
Restoring packages for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj...
C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj : error NU1202: Package Microsoft.AspNetCore.Blazor.Cli 0.7.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package Microsoft.AspNetCore.Blazor.Cli 0.7.0 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1)
Restore failed in 136.22 ms for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj.
但是,我检查了是否已安装2.1 SDK。
>dotnet --info
.NET Command Line Tools (2.1.202)
Product Information:
Version: 2.1.202
Commit SHA-1 hash: 281caedada
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.202\
Microsoft .NET Core Shared Framework Host
Version : 2.0.9
Build : 1632fa1589b0eee3277a8841ce1770e554ece037
什么原因导致了这里的问题?
答案 0 :(得分:0)
问题已解决。
解决方案:
1.从https://dotnet.microsoft.com/download/dotnet-core/2.1
安装最新的2.1 SDK。
2.将Blazor安装到新的SDK中
3.创建一个新项目。
>dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.805
Commit: cee34dc8d6
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.805\
Host (useful for support):
Version: 2.1.17
Commit: 7b9e4ef7c1
.NET Core SDKs installed:
1.1.10 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.805 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
C:\<PathToProject>dotnet new -i Microsoft.AspNetCore.Blazor.Templates
Restore completed in 2.84 sec for C:\Users\XXXXXX\.templateengine\dotnetcli\v2.1.805\scratch\restore.csproj.
Usage: new [options]
Options:
-h, --help Displays help for this command.
-l, --list Lists templates containing the specified name. If no name is specified, lists all templates.
-n, --name The name for the output being created. If no name is specified, the name of the current directory is used.
-o, --output Location to place the generated output.
-i, --install Installs a source or a template pack.
-u, --uninstall Uninstalls a source or a template pack.
--nuget-source Specifies a NuGet source to use during install.
--type Filters templates based on available types. Predefined values are "project", "item" or "other".
--force Forces content to be generated even if it would change existing files.
-lang, --language Filters templates based on language and specifies the language of the template to create.
Templates Short Name Language Tags
-------------------------------------------------------------------------------------------------------------------------------
Console Application console [C#], F#, VB Common/Console
Class library classlib [C#], F#, VB Common/Library
Unit Test Project mstest [C#], F#, VB Test/MSTest
NUnit 3 Test Project nunit [C#], F#, VB Test/NUnit
NUnit 3 Test Item nunit-test [C#], F#, VB Test/NUnit
xUnit Test Project xunit [C#], F#, VB Test/xUnit
Razor Page page [C#] Web/ASP.NET
MVC ViewImports viewimports [C#] Web/ASP.NET
MVC ViewStart viewstart [C#] Web/ASP.NET
Blazor (hosted in ASP.NET server) blazorhosted [C#] Web/Blazor/Hosted
Blazor Library blazorlib [C#] Web/Blazor/Library
Blazor (Server-side in ASP.NET Core) blazorserverside [C#] Web/Blazor/ServerSide
Blazor (standalone) blazor [C#] Web/Blazor/Standalone
ASP.NET Core Empty web [C#], F# Web/Empty
ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC
ASP.NET Core Web App razor [C#] Web/MVC/Razor Pages
ASP.NET Core with Angular angular [C#] Web/MVC/SPA
ASP.NET Core with React.js react [C#] Web/MVC/SPA
ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
Razor Class Library razorclasslib [C#] Web/Razor/Library/Razor Class Library
ASP.NET Core Web API webapi [C#], F# Web/WebAPI
global.json file globaljson Config
NuGet Config nugetconfig Config
Web Config webconfig Config
Solution File sln Solution
Examples:
dotnet new mvc --auth Individual
dotnet new viewimports --namespace
dotnet new --help
C:\<PathToProject>dotnet new blazor -o TestBlazorApp
The template "Blazor (standalone)" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on TestBlazorApp\TestBlazorApp.csproj...
Restore completed in 3.56 sec for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj.
Restore completed in 2.22 min for C:\<PathToProject>\TestBlazorApp\TestBlazorApp.csproj.
Restore succeeded.