如何从 kproj 引用 csproj [英] How to reference csproj from kproj

查看:13
本文介绍了如何从 kproj 引用 csproj的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 VS2015ASP.NET vNext,并在尝试将 vNext 类库 (kproj) 中的引用添加到常规类库时陷入困境(csproj) 在同一个解决方案中.Visual Studio 2015 显示以下错误消息:

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

是否可以从 vNext 类库中添加对 csproj 的引用?

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

推荐答案

注意: kpm 命令已被 dnu 取代.

Note: The kpm command has been replaced by dnu.

Visual Studio 2015 预览版(截至撰写本文时)随 ASP.NET 5 稳定版 beta1 一起提供.在此版本中,无法从 ASP.NET 5 项目中引用 csproj 项目.

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.

但是,在 ASP.NET 5 的开发源中引入了命令 kpm wrap 以支持从 ASP.NET 5 项目中引用 csproj 项目.请参阅 aspnet/KRuntime 存储库中的 github issue #827pull request #875 关闭了问题.

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.

这是一个如何使用 kpm wrap 的示例:

Here is an example how you would use kpm wrap:

确保最新版本的 KRuntime 已安装(用 kvm list 命令检查)(我用 1.0.0-beta2-10709 版本测试了这个).

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

创建一个 ASP.NET 5 类库项目,我使用了名称 ClassLibrary1.

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

创建一个普通的"csproj 类库,我将其命名为 ClassLibrary2(确保将其放在 src 文件夹中).

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

从命令行,从 solutiondirectory 运行命令

From the commandline, from the solutiondirectory run the command

kpm wrap .srcClassLibrary2

这给出了输出:

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

现在在 ClassLibrary1(即 ASP.NET 5)的 project.json 中,您可以添加对 ClassLibrary2 的引用:

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

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

注意:kpm wrap 对我来说使用 cmd 无法正常运行,我需要启动 powershell 才能使其运行.

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

这篇关于如何从 kproj 引用 csproj的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆