今天尝试了下Ubuntu上运行NET程序,按照 https://github.com/aspnet/Home 的指引,一步一步来:
1.安装DNVM(原名KVM)
Linux控制台下输入
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
2.安装DNX(原名KRE)
dnvm upgrade
3.下载github上的实例代码
git clone [email protected]:aspnet/Home.git
4.进入Console示例,准备运行示例代码
dnx . run
结果看到提示:
/root/.dnx/runtimes/dnx-mono.1.0.0-beta5-11394/bin/dnx: line 14: exec: mono: not found
看样子是必须依赖于Mono:此处做以解释,在oschina博客中看到一段话(如下):
在非windows系统上运行ASP.NET vNext应用有如下两种方式. 首先需要安装Mono. 这块基本上没啥难度,但由于目前还有发布安装包,可能会碰到一些问题,很多补丁都是打在mono的源码里.如此,我们需要从gitHub上下载最新的代码然后构建出含有所有补丁的版本. 另一种方法就是安装 “K运行环境” 或简称KRE. 这是些命令行运行并构建(这块没什么区别)新生成的project.json文件. KRE的安装过程是由 “K Version Manager” (KVM)管理的. 这个可以安装多个版本的KRE 并可以方便的在不同版本间切换.
但在https://github.com/aspnet/Home中,文档上明确说明了,在linux中,依赖于Mono3.4.1 Or later
Minimum Requirements These are the current minimum requirements for the latest preview release. They do not necessarily represent what the final minimum requirements will be. Windows Windows 7 or Windows Server 2008 R2. .NET 4.5.1 for hosting in IIS OS X/Linux Mono 3.4.1 or later (Note: On OS X use the Homebrew formula specified below to install the required version of Mono) bash or zsh and curl
有些同学可能会问,不是可以使用coreclr吗? github主页上也给出了明确说明(今天时间2015-3-28),注意加粗字体部分,目前在OSX/LINUX上没有可用的Core CLR,只支持Mono45和x86(32位)。
不过OSX/LINUX可用的Core CLR会很快到来。
Switching to Core CLR By default when running ASP.NET 5 applications on the Windows platform you are running on the full .NET Framework. You can switch to use the new Cloud Optimized runtime, or Core CLR, using the DNVM command. Run dnvm upgrade -runtime CoreCLR This command gets the latest Core CLR version of the DNX and sets it as your default. The -runtime CoreCLR switch tells it to use Core CLR. You can use -r CLR to target desktop again. Run dnx . web to run on WebListener. The first line of your output should say "Loaded Module: dnx.core45.dll" instead of "Loaded Module: dnx.net45.dll" The HelloWeb app should work the same as when running on the full desktop .NET Framework but now as a fully self-contained app with true side-by-side versioning support. NOTE: There are many APIs from the .NET Framework that are not yet available when running on Core CLR. This set should get smaller and smaller as time goes on. NOTE: There is no Core CLR currently available on OSX/Linux. There is only a single platform (mono45) and a single architecture (x86).
那么到这里为止,我们的程序还没有跑起来,我们首先要安装Mono,版本要求3.4.1 或更高,apt-get安装的版本是3.12.1(参考http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list sudo apt-get update
#我的环境是Ubuntu12.04 所以要执行
echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
apt-get install mono-complete
安装完成之后,进入~/Home/samples/Console 执行命令
dnx . run
输出 Hello World ,至此运行成功
进入~/Home/samples/HelloMvc,尝试运行Web项目
dnx . kestrel
提示没有安装完整的packages
dun restore
还原所有的nuget包,再次执行 dnx . kestrel,仍然报错,提交了一个issue:https://github.com/aspnet/Home/issues/420
看样子现在开始MVC6在linux运行还为时过早,等稳定了的吧。Mono已经开发了很多年了,跑NET应用已经比较稳定了。而我测试的ASPNET5、DNVM仍然是一个非常新的东西。所以此处运行示例有问题,并不代表,Mono本身有什么问题.