标签:
VS2015 Preview 发布已经有一段时间了。根据官方的说法ASP.NET 5 做了一些重大改进和设计。
优化了的开发框架有如下几个特性:
等。。。
对于asp.net 5 的一些改变相信一些朋友发现的比我还多,在这方面做了一些大的改变,微软还真是颠覆了一下自己,这也是一个值得大家期待和进步的地方,对于构建web应用程序来说他也是一个比较理想的选择。那么在asp.net 5 的学习过程中,相信热爱技术的朋友已经碰到和我一样的问题了,在Visual Studio 2015 Preview beta1 中还没有办法从ASP.NET 5项目引用的之前版本csproj项目,当我们引用类库时会发现报错提示如下:
不支持引用下列项目:**.csproj。顾名思义,版本不兼容那么如何做到版本兼容呢?方法肯定是有的,例如发布NuGet包或者做版本迁移,相信有些朋友对发布NuGet包不会太陌生,那么我们就学习做版本迁移吧。[注:版本迁移,是作者根据自己的理解翻译的。]
安装KVM(K Version Manager)
需要在Windows Cmd.exe或者VS Cmd.exe上运行下面的命令,该命令将下载并运行安装KVM在当前用户。(需要管理管权限)
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString(‘https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1‘))"
如果安装成功如下图所示:
然后在命令行中输入:
kpm wrap .\src\ClassLibrary
结果如下:
此时,我们可以修改project.json文件:
... "dependencies": { "ClassLibrary": "" }, ...
英语好的朋友可以结合下面原文看下!
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 solution directory run the command
kpm wrap .\src\ClassLibrary2
This gives the output:
Wrapping project ‘ClassLibrary2‘ for ‘.NETFramework,Version=v4.5‘
Source C:\Users\andersns\Source\ClassLibrary1\src\ClassLibrary2\ClassLibrary2.csproj
Target C:\Users\andersns\Source\ClassLibrary1\wrap\ClassLibrary2\project.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.
对了,伙伴们Visual Studio 2015 Preview beta2 做了改进并且支持引用C#标准项目。
链接:http://blogs.msdn.com/b/visualstudio/archive/2015/01/16/visual-studio-2015-cpt-5-now-available.aspx
摸索门径之ASP.NET 5 出现 "The following projects are not supported as references:"**.csproj""的原因
标签:
原文地址:http://www.cnblogs.com/KoalaAPI/p/4253723.html