1

I started a new ASP.NET Core WebApi project from Visual Studio. Project initialized and started without problem.

Now I want to add a .NET Core class library to contain logic separated from the app. So I right-clicked the src folder, chose Add -> New Project and chose Class LOibrary (.NET Core).

In my class library I created a new middleware:

namespace MyClassLib
{
    public class MyMiddleware
    {
        private readonly RequestDelegate _next;

        public MyMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task Invoke(HttpContext context)
        {
            await _next.Invoke(context);
        }
    }
}

And created extension method for it:

namespace MyClassLib
{
    public static class MyMiddlewareExtensions
    {
        public static IApplicationBuilder UseMyMiddleware(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<MyMiddleware>();
        }
    }
}

So far nothing fancy.

In my web API I added a reference to that project:

"dependencies": {
    "Microsoft.NETCore.App": {
        "version": "1.0.0",
        "type": "platform"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "MyClassLib": "1.0.0-*"
}

But when I try to use my new class library in my WebApi startup class it doesn't seem to recognize it - showing the using MyClassLib in red (error) and not allowing me to use any of the classes inside it.

What am I missing here? previous to .NET Core this is something I used to do all the time...

EDIT

Strange, but if I disable ReSharper than everything works. If I re-enable ReSharper than it shows errors again but still compiles. I've seen posts on GitHub from people who encountered this problem on RC1 - but it was mentioned that it was fixed. Anyone knows how I can continue working with ReSharper and .NET Core?

1 Answer 1

2

The problem might be that there's an existing package in the NuGet gallery called MyClassLib that has a version 1.0.0, so NuGet is probably pulling that down and referencing that.

In order to instruct the project system to use the local project, instead of a published package, try doing

"MyClassLib": { "target": "project" }
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for answering. Please see my edit in original post regarding ReSharper
I'd check out the ReSharper EAP program. I'm not sure if .NET Core is fully supported yet, but they've done tons of bugfixes in the 2016.2 release.
I was having similar issues with ReSharper and am currently on the EAP release. Still a little iffy at times with references, but, improved overall.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.