自从知道微软用dotnet cli取代dnx之后,一直在等dotnet cli支持asp.net core。。。
昨天看到这篇新闻(ASP.NET Core 1.0 Hello World)后,才知道原来dotnet cli早就支持asp.net core了,而且在github上有专门的示例程序。
于是,立马想在mac上体验一下。
首先去 http://dotnet.github.io/getting-started/ 下载并安装mac版的dotnet cli —— dotnet-osx-x64.latest.pkg。安装成功之后,就可以在terminal中运行dotnet命令:
$ dotnet
.NET Command Line Tools (1.0.0-beta-001556)
Usage: dotnet mmon-options] mmand] guments]
然后用git命令从github上签出 https://github.com/aspnet/cli-samples
git clone https://github.com/aspnet/cli-samples
cd cli-samples
然后运行dotnet restore命令安装nuget包包,出现了错误:
dotnet restore
log : Restoring packages for /Git/dotnet/cli-samples/HelloMvcApi/project.json...
log : Restoring packages for /Git/dotnet/cli-samples/HelloWebFull/project.json...
log : Restoring packages for /Git/dotnet/cli-samples/HelloMvc/project.json...
log : Restoring packages for /Git/dotnet/cli-samples/HelloWeb/project.json...
error: The type initializer for 'Crypto' threw an exception.
error: Unable to load DLL 'System.Security.Cryptography.Native': The specified module could not be found.
error: (Exception from HRESULT: 0x8007007E)
出现这个问题是由于我电脑上的openssl版本低(OpenSSL 0.9.8),dotnet cli需要的版本是OpenSSL 1.0.1或1.0.2。用homebrew安装最新版的openssl:
brew install openssl
安装之后,虽然openssl version显示的还是0.9.8,但这时dotnet restore命令已经可以正常运行了。
log : Restoring packages for /Git/dotnet/cli-samples/HelloWebFull/project.json...
log : Restoring packages for /Git/dotnet/cli-samples/HelloMvcApi/project.json...
log : Restoring packages for /Git/dotnet/cli-samples/HelloWeb/project.json...
log : Restoring packages for /Git/dotnet/cli-samples/HelloMvc/project.json...
info : GET https://www.myget.org/F/aspnetcidev/api/v3/flatcontainer/netstandard.library/index.json
原以为大功告成了,结果却是在dotnet restore期间nuget包包总是安装失败,比如出现下面的错误:
error: Failed to download package from 'https://www.myget.org/F/aspnetcidev/api/v3/flatcontainer/microsoft.aspnetcore.iisplatformhandler/1.0.0-rc2-16280/microsoft.aspnetcore.iisplatformhandler.1.0.0-rc2-16280.nupkg'.
error: The HTTP request to 'GET https://myget-2e16.kxcdn.com/privatefeedaspnetcidev/Microsoft.AspNetCore.IISPlatformHandler-1.0.0-rc2-16280?sv=2014-02-14&sr=b&sig=ARjy3JzGc36F5tS6EyvjEQWpI0JHL56vOkiJW8U9LV8%3D&st=2016-02-26T13:55:00Z&se=2016-02-26T15:05:00Z&sp=r&rscc=max-age%3D3600&rsct=binary%2Foctet-stream&rscd=filename%3DMicrosoft.AspNetCore.IISPlatformHandler.1.0.0-rc2-16280.nupkg' has timed out after 100000ms.
奇怪的是,不能安装的包包,通过浏览器或curl命令都能下载。而在linux电脑上没这个问题,dotnet restore一切正常,dotnet run轻松将asp.net core示例站点运行了起来。算了,直接在linux上折腾吧,暂时不在mac上尝试了。