我通过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 && <2.2.0)。
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安装程序(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)
答案 0 :(得分:1)
似乎您使用的是EFCore
版本的2.2
,而项目基础dotnet
的版本是2.1
。在这种情况下,如果您的系统上没有dotnet
版本2.2
,则必须将EFCore
降级为2.1.*
版本。