Я создал новый проект asp.net через cli, например: 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). </p>
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
Я так и делаю.и тогда я получу другую ошибку.
Спасибо
Ок, я установил версию донета .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
Оке сделал это.См .:
<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)