Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

c# - How to reference csproj from kproj

I was playing around with VS2015 and ASP.NET vNext, and got stuck on trying to add a reference from vNext class library (kproj) to a regular class library (csproj) in the same solution. Visual Studio 2015 shows the following error message:

"The following projects are not supported as references".

Is it possible at all to add references to csproj from vNext class libraries?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Note: The kpm command has been replaced by dnu.

Visual Studio 2015 Preview (as of writing this) comes with the ASP.NET 5 stable release beta1. In this version there is no way to reference a csproj project from an ASP.NET 5 project.

However, on the development feed of ASP.NET 5 the command kpm wrap was introduced to support referencing csproj-projects from ASP.NET 5 projects. See the github issue #827 in the aspnet/KRuntime repository and pull request #875 which closes the issue.

Here is an example how you would use kpm wrap:

Make sure the newest version of the KRuntime is installed (check this with the kvm list command) (I tested this with version 1.0.0-beta2-10709).

Create an ASP.NET 5 class library project, I used the name ClassLibrary1.

Create a "normal" csproj class library, I named this ClassLibrary2 (make sure you put this in the src folder).

From the commandline, from the solutiondirectory run the command

kpm wrap .srcClassLibrary2

This gives the output:

Wrapping project 'ClassLibrary2' for '.NETFramework,Version=v4.5'
 Source C:UsersandersnsSourceClassLibrary1srcClassLibrary2ClassLibrary2.csproj
   Target C:UsersandersnsSourceClassLibrary1wrapClassLibrary2project.json
   Adding bin paths for '.NETFramework,Version=v4.5'
     Assembly: ../../src/ClassLibrary2/obj/debug/ClassLibrary2.dll
     Pdb: ../../src/ClassLibrary2/obj/debug/ClassLibrary2.pdb

Now in the project.json of ClassLibrary1 (which is ASP.NET 5) you can add a reference to ClassLibrary2 with this:

...
"dependencies": {
    "ClassLibrary2": ""
},
...

Note: kpm wrap did not run properly for me with cmd, I needed to launch powershell to make it run.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...