ASP.NET Core Web API和OpenIddict

时间:2017-04-25 13:00:49

标签: asp.net-core openiddict

我尝试将OpenIddict用于我的asp.net core web api项目。我按照here编写的说明进行操作,但是当我尝试构建项目时,我收到以下错误

  

无法解析' OpenIddict.Mvc(> = 1.0.0)' for' .NETCoreApp,Version = v1.1'。

我已经通过Visual Studio 2017创建了该项目(我想我默认安装了最新的.NET Core工具)。有什么想法吗?

更新 说明的第1步说明您必须更新软件包以引用ASP.NET Core RTM软件包。那意味着什么?

我的.csproj文件

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="AspNet.Security.OAuth.Validation" Version="$(AspNetContribOpenIdExtensionsVersion)" />
    <PackageReference Include="OpenIddict" Version="$(OpenIddictVersion)" />
    <PackageReference Include="OpenIddict.EntityFrameworkCore" Version="$(OpenIddictVersion)" />
    <PackageReference Include="OpenIddict.Mvc" Version="$(OpenIddictVersion)" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\iBoard.Repositories\iBoard.Repositories.csproj" />
  </ItemGroup>

</Project>

我也试过了Version="1.0.0-*"

1 个答案:

答案 0 :(得分:2)

在.csproj中添加缺少的OpenIddictVersion / AspNetContribOpenIdExtensionsVersion属性,它应该有效:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <AspNetContribOpenIdExtensionsVersion>1.0.0-*</AspNetContribOpenIdExtensionsVersion>
    <OpenIddictVersion>1.0.0-*</OpenIddictVersion>
  </PropertyGroup>

</Project>

或者,您也可以直接硬编码正确的版本:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <ItemGroup>
    <PackageReference Include="AspNet.Security.OAuth.Validation" Version="1.0.0-*" />
    <PackageReference Include="OpenIddict" Version="1.0.0-*" />
    <PackageReference Include="OpenIddict.EntityFrameworkCore" Version="1.0.0-*" />
    <PackageReference Include="OpenIddict.Mvc" Version="1.0.0-*" />
  </ItemGroup>

</Project>