Search code examples
c#.netasp.net-corenugetasp.net-core-identity

Which nuget contains SecurityStampValidatorOptions


In a dotnet library project I need access to SecurityStampValidatorOptions.

That appears to be part of the "Microsoft.AspNetCore.Identity" assembly, whose nuget package is deprecated.

So I tried referencing Microsoft.AspNetCore.Identity.EntityFrameworkCore, but that also doesn't help. I get

The type or namespace name 'SecurityStampValidatorOptions' does not exist in the namespace 'Microsoft.AspNetCore.Identity' (are you missing an assembly reference?)

(It is definitely in that namespace though, and in my main ASP.NET Core project, it works.)

Where is that class defined?


Solution

  • The ASP.NET Core reference packages are imported into a project through the project's SDK attribute instead of specific NuGet Gallery PackageReference elements. Microsoft.AspNetCore.App.Ref is "not meant to be used as a normal PackageReference" because the ASP.NET Core libraries don't get bundled with the app, they are expected to exist when run on a computer with the ASP.NET Core Runtime installed.

    Project SDK

    You can try changing your library project's .csproj file to use the ASP.NET Core SDK by appending .Web to the /Project/@Sdk attribute:

    <Project Sdk="Microsoft.NET.Sdk.Web">
        <PropertyGroup>
            <OutputType>Library</OutputType>
        </PropertyGroup>
    </Project>
    

    This will add a framework reference to Microsoft.AspNetCore.App in your library project, which will include Microsoft.AspNetCore.Identity.dll, among many other assemblies.

    Framework reference

    Alternatively, you can manually add a framework reference to these libraries without changing the project SDK.

    <Project Sdk="Microsoft.NET.Sdk">
        <ItemGroup>
            <FrameworkReference Include="Microsoft.AspNetCore.App" />
        </ItemGroup>
    </Project>
    

    For more information, see Use ASP.NET Core APIs in a class library.