13

I cant figure out why Startup.cs is throwing this error. I tried the solutions suggested here (including restarting my machine and running dotnet restore) with no luck. Any ideas?

CS1061 'IServiceCollection' does not contain a definition for 'AddSpaStaticFiles' and no accessible extension method 'AddSpaStaticFiles' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

enter image description here

using statements at the top of startup.cs:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Myproject.Models;

using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
//Install-Package Microsoft.AspNetCore.Session
//Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection

My .csproj file contains:

  <ItemGroup>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.1.1" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.2.4" />
    <PackageReference Include="Flurl.Http" Version="2.2.1" />
    <PackageReference Include="jQuery" Version="3.3.1" />
    <PackageReference Include="jQuery.Validation" Version="1.17.0" />
    <PackageReference Include="LeanKit.API.Client" Version="1.2.6" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />

    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final" />
  </ItemGroup>
user184994
  • 15,680
  • 1
  • 33
  • 45
Rilcon42
  • 7,248
  • 11
  • 51
  • 127

1 Answers1

21

You need to install these two NuPackages:

enter image description here

We can see this is an extension method in the assembly of Microsoft.AspNetCore.SpaServices.Extensions

enter image description here

Lee Liu
  • 1,602
  • 1
  • 7
  • 12
  • 1
    That worked- I installed it thru the UI and got an error "Must install Microsoft.CodeAnalysis". Once I did that and followed the steps above everything worked fine – Rilcon42 Nov 13 '18 at 16:00