alexxjk
alexxjk

Reputation: 1701

Can not add reference to .NET Core class library in ASP.NET Core project

I've created a new ASP.NET Core project and a class library for it in VS 2015 (Update 3).

This is how project.json looks like:

    {
      "version": "1.0.0-*",

      "dependencies": {
        "NETStandard.Library": "1.6.0"
      },

      "frameworks": {
        "netstandard1.6": {
          "imports": "dnxcore50"
        }
      }
    }

And this is a project.json of the ASP.NET Project:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "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"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Now I can't add my class library to my site as 'dependency can't be resolved'.

Upvotes: 2

Views: 2035

Answers (1)

Nate Barbettini
Nate Barbettini

Reputation: 53600

I didn't see a reference to your library in your application's dependencies section. If your library and your application are in the same solution, make sure you use target: project like so:

project.json of ASP.NET Core project:

"dependencies": {
    ...
    "MyLibrary": {
        "version": "1.0.0",
        "target": "project"
    }
}

Otherwise, NuGet will look for your library as a package instead of looking in the solution.

Upvotes: 1

Related Questions