本文介绍了无法在 ASP.NET Core 项目中添加对 .NET Core 类库的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS 2015(更新 3)中创建了一个新的 ASP.NET Core 项目和一个类库.

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

这是 project.json 的样子:

    {
      "version": "1.0.0-*",

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

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

这是 ASP.NET 项目的 project.json:

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'.

推荐答案

我在您的应用程序的 dependencies 部分中没有看到对您的库的引用.如果您的库和应用程序在同一个解决方案中,请确保像这样使用 target: project:

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:

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

否则,NuGet 会将您的库作为包查找,而不是在解决方案中查找.

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

这篇关于无法在 ASP.NET Core 项目中添加对 .NET Core 类库的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 11:03