【发布时间】:2019-02-25 16:53:58
【问题描述】:
我通过 cli 创建了一个新的 asp.net 项目,如下所示:dotnet new Angular。
这样我就可以运行该网站了。现在我添加了一个 dbContext,如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<VegaDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Default")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
但现在我无法再运行该应用程序,因为我收到以下错误:
D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj:错误 NU1107:检测到版本冲突 Microsoft.Extensions.Caching.Abstractions。安装/参考 Microsoft.Extensions.Caching.Abstractions 2.2.0 直接到项目 aspnetAngular 来解决这个问题。 D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj:错误 NU1107:aspnetAngular -> Microsoft.EntityFrameworkCore 2.2.2 -> Microsoft.Extensions.Caching.Memory 2.2.0 -> Microsoft.Extensions.Caching.Abstractions (>= 2.2.0) D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj:错误 NU1107:aspnetAngular -> Microsoft.AspNetCore.App 2.1.1 -> Microsoft.Extensions.Caching.Abstractions (>= 2.1.1 &&
The build failed. Please fix the build errors and run again.
这就是我的 csproj 文件的样子:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
<!-- Set this to true if you enable server-side prerendering -->
<BuildServerSideRenderer>false</BuildServerSideRenderer>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.sqlServer" Version="2.2.2" />
</ItemGroup>
<ItemGroup>
<!-- Don't publish the SPA source files, but do show them in the project files list -->
<Content Remove="$(SpaRoot)**" />
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
</Project>
所以我的问题是:如何解决这个问题?
因为当我安装缺少的库 - Microsoft.Extensions.Caching.Abstractions 2.2.0 时,我看起来像是在循环中
我这样做。然后我会得到另一个错误。
谢谢
好的,我安装了 donet 版本 .NET Core 2.2 SDK - Windows x64 Installer (v2.2.104)
但我仍然收到此错误:
Starting OmniSharp server at 2/22/2019, 4:58:53 PM
Target: d:\Mijn Documents\UDEMY\aspnetAngular
OmniSharp server started.
Path: C:\Users\User.USER-PC\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\OmniSharp.exe
PID: 12764
[info]: OmniSharp.Stdio.Host
Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 3 MSBuild instance(s)
1: Visual Studio Community 2017 15.9.28307.105 - "D:\Program Files (x86)\VisualStudio_2017\MSBuild\15.0\Bin"
2: Visual Studio Enterprise 2017 15.0.26228.64 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin"
3: StandAlone 15.0 - "C:\Users\User.USER-PC\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Community 2017 15.9.28307.105 - "D:\Program Files (x86)\VisualStudio_2017\MSBuild\15.0\Bin"
[info]: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'd:\Mijn Documents\UDEMY\aspnetAngular'.
[info]: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
No solution files found in 'd:\Mijn Documents\UDEMY\aspnetAngular'
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'd:\Mijn Documents\UDEMY\aspnetAngular'.
[info]: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj
[info]: OmniSharp.WorkspaceInitializer
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'd:\Mijn Documents\UDEMY\aspnetAngular' on host 14556.
[warn]: OmniSharp.MSBuild.ProjectLoader
Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore 2.2.2 was resolved.
[warn]: OmniSharp.MSBuild.ProjectLoader
Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.Abstractions (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.Abstractions 2.2.2 was resolved.
[warn]: OmniSharp.MSBuild.ProjectLoader
Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.Analyzers (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.Analyzers 2.2.2 was resolved.
[warn]: OmniSharp.MSBuild.ProjectLoader
Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.Relational (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.Relational 2.2.2 was resolved.
[warn]: OmniSharp.MSBuild.ProjectLoader
Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.SqlServer (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.SqlServer 2.2.2 was resolved.
[fail]: OmniSharp.MSBuild.ProjectLoader
Version conflict detected for Microsoft.Extensions.Caching.Abstractions. Install/reference Microsoft.Extensions.Caching.Abstractions 2.2.0 directly to project aspnetAngular to resolve this issue.
aspnetAngular -> Microsoft.EntityFrameworkCore 2.2.2 -> Microsoft.Extensions.Caching.Memory 2.2.0 -> Microsoft.Extensions.Caching.Abstractions (>= 2.2.0)
aspnetAngular -> Microsoft.AspNetCore.App 2.1.1 -> Microsoft.Extensions.Caching.Abstractions (>= 2.1.1 && < 2.2.0).
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file 'd:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj'.
d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj
d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj(0,0): Error: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore 2.2.2 was resolved.
d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj(0,0): Error: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.Abstractions (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.Abstractions 2.2.2 was resolved.
d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj(0,0): Error: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.Analyzers (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.Analyzers 2.2.2 was resolved.
d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj(0,0): Error: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.Relational (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.Relational 2.2.2 was resolved.
d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj(0,0): Error: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.SqlServer (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.SqlServer 2.2.2 was resolved.
d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj(0,0): Error: Version conflict detected for Microsoft.Extensions.Caching.Abstractions. Install/reference Microsoft.Extensions.Caching.Abstractions 2.2.0 directly to project aspnetAngular to resolve this issue.
aspnetAngular -> Microsoft.EntityFrameworkCore 2.2.2 -> Microsoft.Extensions.Caching.Memory 2.2.0 -> Microsoft.Extensions.Caching.Abstractions (>= 2.2.0)
aspnetAngular -> Microsoft.AspNetCore.App 2.1.1 -> Microsoft.Extensions.Caching.Abstractions (>= 2.1.1 && < 2.2.0).
[fail]: OmniSharp.MSBuild.ProjectManager
Attemped to update project that is not loaded: d:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj
我不明白。我收到此错误:
error: Package Microsoft.AspNetCore.App 2.2.2 is not compatible with netcoreapp2.1 (.NETCoreApp,Version=v2.1). Package Microsoft.AspNetCore.App 2.2.2 supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
error: Package 'Microsoft.AspNetCore.App' is incompatible with 'all' frameworks in project 'D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj'.
但如果我这样做:dotnet --version
我得到了正确的版本:2.2.104
Oke 做到了。见:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
<!-- Set this to true if you enable server-side prerendering -->
<BuildServerSideRenderer>false</BuildServerSideRenderer>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.sqlServer" Version="2.2.2" />
</ItemGroup>
<ItemGroup>
<!-- Don't publish the SPA source files, but do show them in the project files list -->
<Content Remove="$(SpaRoot)**" />
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
</Project>
但如果我运行该项目,我仍然会收到此错误:
D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj : error NU1605: Detected package downgrade: Microsoft.AspNetCore.SpaServices.Extensions from 2.2.0 to 2.1.1. Reference the package directly from the project to select a different version.
D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj : error NU1605: aspnetAngular -> Microsoft.AspNetCore.App 2.2.0 -> Microsoft.AspNetCore.SpaServices.Extensions (>= 2.2.0 && < 2.3.0)
D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj : error NU1605: aspnetAngular -> Microsoft.AspNetCore.SpaServices.Extensions
(>= 2.1.1)
所以我找到了一个“解决方案”——你必须删除 PacketReference,所以我这样做了,但现在我收到了这个错误:
D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj : error NU1605: Detected package downgrade: Microsoft.AspNetCore.Razor.Design
from 2.2.0 to 2.1.2. Reference the package directly from the project to select a different version.
D:\Mijn Documents\UDEMY\aspnetAngular\aspnetAngular.csproj : error NU1605: aspnetAngular -> Microsoft.AspNetCore.App 2.2.0 -> Microsoft.AspNetCore.Razor.Design (>= 2.2.0 && < 2.3.0)
【问题讨论】:
-
安装新的
dotnet:2.2后,您是否为您的项目设置了新版本的dotnet?检查项目的属性。 -
嗯,我正在使用 Visual Studio 代码。那么如何在 Visual Studio 代码中做到这一点呢?
-
您打开与您的工作项目相关的
.csproj文件并编辑<TargetFramework>值。在旅游的情况下,它应该被替换为netcoreapp2.2。 -
好的,谢谢。我这样做了。查看更新后的帖子
标签: c# asp.net-core command-line-interface