Search code examples
c#asp.netasp.net-core.net-coreclass-library

Can't reference other projects from ASP.NET Core project


I have a .NETCoreApp 1.1 web application, and I added a reference to a bunch of other projects that also target .NETCoreApp 1.1. But some reason I can't use the classes in those projects. When I use the class name, resharper/VS doesn't give me suggestions to import the correct namespace, and when I manually type a using for the proper namespace, it's not recognized. I should note that between class libraries I can link to other projects just fine, but it breaks down between an ASP.NET Project and a class library. How do I do this?

This is what my web app looks like:

<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="WindowsAzure.Storage" Version="8.1.1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Commands\Commands.csproj" />
  </ItemGroup>

</Project>

And one of the referenced projects:

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

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

</Project>

Here is my code:

using System;
using System.Threading.Tasks;

namespace Worker.Handlers
{
    public class Test1CommandHandler : IHandler<Test1Command>
    {
        public Task HandleAsync(Test1Command message)
        {
            throw new NotImplementedException();
        }

        public Task HandlePoisonAsync(Test1Command message)
        {
            throw new NotImplementedException();
        }
    }
}

In the class library:

namespace Commands
{
    public class Test1Command
    {
        public string Foo { get; set; }

        public string Bar { get; set; }
    }
}

Solution

  • It turned out to be a ReSharper issue. I temporarily disabled it and now everything works fine. Very annoying.

    Also: lightweight solution loading may have something to do with it. Try disabling that.