Search code examples
asp.net-coreopeniddict

ASP.NET Core Web API and OpenIddict


I'm trying to use OpenIddict to my asp.net core web api project. I have followed the instructions written here but when i try to build the project i get the following error

Unable to resolve 'OpenIddict.Mvc (>= 1.0.0)' for '.NETCoreApp,Version=v1.1'.

I have created the project through Visual Studio 2017 (I suppose i have the latest .NET Core tooling installed by default). Any ideas?

UPDATE: The 1st step of the instructions says that you have to update your packages to reference the ASP.NET Core RTM packages. What that means?

And my .csproj file

<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>

I have also tried with Version="1.0.0-*"


Solution

  • Add the missing OpenIddictVersion/AspNetContribOpenIdExtensionsVersion properties in your .csproj and it should work:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
      <PropertyGroup>
        <TargetFramework>netcoreapp1.1</TargetFramework>
        <AspNetContribOpenIdExtensionsVersion>1.0.0-*</AspNetContribOpenIdExtensionsVersion>
        <OpenIddictVersion>1.0.0-*</OpenIddictVersion>
      </PropertyGroup>
    
    </Project>
    

    Alternatively, you can also directly hardcode the right version:

    <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>