嘗試在mac上用dotnet cli運行asp.net core示例程序


自從知道微軟用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上嘗試了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM