简体   繁体   中英

VS2015 add reference for Class Library

I have created a project in VS2015, structure as below:

Solution1

  • BookStore.ClassLibrary1 => Class Library (Package)
  • BookStore.ClassLibrary2 => Class Library
  • BookStore.Web => MVC5

In BookStore.Web, I can reference BookStore.ClassLibrary2 , but fail to reference BookStore.ClassLibrary1 .

It shows an error " A reference to 'ClassLibrary1' could not be added. "

My question is how to reference a Class Library (Package) in VS2015? Thank you so much!

Looks like your ClassLibrary1 project is a Class Library Package, not a class library project. Class Library Package is used to create Nuget packages that can target any platform.

There are a number of benefits of ASP.NET 5 Class Library projects (.kproj) over Class Library projects (.csproj):

ASP.NET 5 class libraries easily support cross-compiling projects to multiple targets, such as aspnet50, aspnetcore50, net45, and various other portable class library variations. This includes rich Visual Studio support for Intellisense to notify you which APIs are available for which targets. NuGet packages are automatically created, which is an extremely common thing to do with class libraries. Better productivity when it comes to things like automatically refreshing Solution Explorer when the file system changes. Fewer conflicts in source control when trying to merge conflicting changes in the *.csproj file. Can be compiled cross-platform (in part because it doesn't depend on MSBuild) You can reference a *.csproj project from a *.kproj project (this was just made a lot easier with the new preview of Visual Studio 2015), but it was always possible with some manual steps.

Why does the name have "ASP.NET" in it?

As far as the names goes, it's a relic of history that will soon be addressed. The new project type is useful far beyond ASP.NET 5 applications. Expect to see new names in a future preview of Visual Studio:

.NET Console Application (Cross-platform) .NET Class Library (Cross-platform) With the release of Visual Studio 2015 RC you can see the updated project template names:

Class Library (Package) Console Application (Package) These use the project.json file and the .NET Execution Environment (DNX) to build, run, and package (into a NuGet package) the project.

These project templates continue to show up in the New Project dialog under the "Web" node, but now also show up in the main "Visual C#" node as well.

Here is a good link as you need to referance a dll that the new clas library does not build. https://evolpin.wordpress.com/2015/01/25/vnext-and-class-libraries/

要么使用普通的旧类库,要么使用Nuget类库 ,将其发布到本地或公共Nuget仓库,然后从那里将其添加到Web项目中。

I doubt about dependency of ClassLibrary1 and I can even see that in your screenshot, 在此输入图像描述

It seems ClassLibrary1 is looking for some dependent dlls, so you might need to add those dll first then you can go ahead and add it. Something similar happens here too

More details about Depencies can gather from this MSDN link you can directly jump to Dependencies node for Bower and NPM dependencies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM