ASP.NET core 搭建於 Deepin 2015.4 記錄

2017-05-13更新,可用,本身傻逼纔會在Linux下用微軟的爛玩意!!!php

最新參考網頁:html

參考網頁:linux

抱歉,微軟的東西比較噁心,網址居然變了,一部分失效了。更改。若有異常,請自行解決。git

1、生活如此不堪

由於開發速度太慢,致使老大看不過去了,直接購買了別人的網站,以前使用PHP開發的,別人的源碼是ASP.NET的,所幸對方提供源碼,要給對方升級?github

2、搭建ASP.NET的工做環境

一直使用Linux Deepin操做系統,已經兩三年了,沒有在電腦上存在Windows系統了,忽然要裝個盜版windows系統,實在不情願,折騰系統太費勁了。遂用 VS Code和ASP.NET Core一塊兒,在Deepin下,能否更好一點呢?就這樣搭建吧。web

3、搭建過程

一、安裝 .NET Core SDK

到這個網頁,點擊下載這個文件,假設下載到 Desktop 桌面。面試

因爲默認不支持 deepin格式,須要修改一下這個腳本。npm

$ gedit ~/Desktop/dotnet-install.sh

搜素 debiandebian.8前,照瓢畫葫蘆,加入 「deepin.15.4"的內容。json

"deepin.15.4")
                    echo "debian"
                    return 0
                    ;;
                "debian.8")
                    echo "debian"
                    return 0
                    ;;
    ```
實現deepin 15.4 也能夠直接安裝。

接着輸入以下命令。

```bash
$ sudo apt-get install curl libunwind8 gettext libicu52
$ sudo su
# mkdir -p /opt/dotnet
# cd /home/<user>/Desktop
# chmod u+x ./dotnet-install.sh
# ./dotnet-install.sh --version 1.0.4 --install-dir /opt/dotnet/

解釋gulp

  • 最開始使用 sudo 直接執行這些命令,發現 dotnet-install.sh 會報錯。無解,遂切換至 root 用戶下安裝。
  • 最後一句的意思:選擇 1.0.4 版本,安裝目錄爲 /opt/dotnet/ 。這樣選擇的緣由,是查到了這裏 https://github.com/dotnet/core-setup/blob/master/README.md 找了一個老版本穩定點的下載。
  • 通過一個漫長的下載過程,可能會成功,也也可能失敗。感受微軟這方面作的比較煩,迫不得已。

接下來就是創建連接了

$ sudo ln -s /opt/dotnet/dotnet /usr/local/bin

二、查看版本

dotnet --version

通常會看到版本號,跟上方的 1.0.4 一致。

三、簡單例子

cd
    mkdir www
    cd www
    mkdir test
    cd test
    dotnet new

新建一個可能會彈出以下問題。

Template Instantiation Commands for .NET Core CLI.

Usage: dotnet new [arguments] [options]

Arguments:
  template  The template to instantiate.

Options:
  -l|--list         List templates containing the specified name.
  -lang|--language  Specifies the language of the template to create
  -n|--name         The name for the output being created. If no name is specified, the name of the current directory is used.
  -o|--output       Location to place the generated output.
  -h|--help         Displays help for this command.
  -all|--show-all   Shows all templates


Segmentation fault

網上搜了好久,說了不少廢話,貌似用以前的解決方案就能夠了。

$ sudo dpkg -i /path/to/libcurl3_7.38.0-4+deb8u3_amd64.deb

其中,libcurl3_7.38.0-4+deb8u3_amd64.deb 是在 debian 官網找到下載的。 下面繼續測試。

$ sudo apt-get purge curl
$ sudo apt-mark hold libcurl3
$ cd ~/www/test
$ dotnet new

可能會彈出以下的界面

Templates                 Short Name      Language      Tags          
----------------------------------------------------------------------
Console Application       console         [C#], F#      Common/Console
Class library             classlib        [C#], F#      Common/Library
Unit Test Project         mstest          [C#], F#      Test/MSTest   
xUnit Test Project        xunit           [C#], F#      Test/xUnit    
ASP.NET Core Empty        web             [C#]          Web/Empty     
ASP.NET Core Web App      mvc             [C#], F#      Web/MVC       
ASP.NET Core Web API      webapi          [C#]          Web/WebAPI    
Solution File             sln                           Solution      

Examples:
    dotnet new mvc --auth None --framework netcoreapp1.1
    dotnet new mvc --framework netcoreapp1.1
    dotnet new --help

輸入以下命令,

$ dotnet new mvc --auth None --framework netcoreapp1.1

新建並初始化,

$   dotnet restore
 $   dotnet run

四、安裝 Yeoman, Bower, Grunt, Gulp, ASP.NET core 等的生成器

本小點內容主要參考該書.

sudo npm install -g yo bower grunt-cli gulp
sudo npm install -g generator-aspnet

解釋

  • 假設你已經成功安裝了 npm,如需請百度怎麼安裝。

五、另一個簡單例子

cd ~/www
    yo aspnet

解釋

  • 按照輸出提示,新建一個 WebLM 的網站,顯示內容以下。
yo aspnet
? ==========================================================================
We're constantly looking for ways to make yo better! 
May we anonymously report usage statistics to improve the tool over time? 
More info: https://github.com/yeoman/insight & http://yeoman.io
========================================================================== Yes

     _-----_     ╭──────────────────────────╮
    |       |    │      Welcome to the      │
    |--(o)--|    │  marvellous ASP.NET Core │
   `---------´   │        generator!        │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

? What type of application do you want to create? Web Application
? Which UI framework would you like to use? Bootstrap (3.3.6)
? What's the name of your ASP.NET application? WebLW

解釋

  • 接下來就是一大堆安裝提示信息了,並有以下內容
Your project is now created, you can use the following commands to get going
    cd "WebLW"
    dotnet restore
    dotnet build (optional, build will also happen when it's run)
    dotnet ef database update (to create the SQLite database for the project)
    dotnet run

解釋

  • 若是提示 bower ECMDERR 之類的信息,可能須要自行安裝一些插件 好比
cd ~/www/WebLW
    bower install

若是沒有報錯,繼續使用上面提示的內容

cd ~/www/WebLW
    dotnet restore
    dotnet build
    dotnet ef database update
    dotnet run

根據提示進入 http://localhost:5000/ 應該能夠看到以下的界面了。 Deepin 15.2 安裝 ASP.NET core

輸入圖片說明

六、安裝 vscode 及其插件

這個比較傻瓜了,直接使用命令便可

sudo apt-get install vscode -y

其餘插件安裝能夠自行百度。 我如今安裝的插件有

  • donjayamanne.githistory-0.0.10
  • ms-vscode.csharp-1.4.0
  • felixfbecker.php-debug-1.9.4
  • ms-vscode.omnisharp-0.3.3
  • Kasik96.format-indent-1.3.0

4、打補丁

如今直接使用命令 code 打開 vscode,發現會彈出

[ERROR] Could not locate an OmniSharp server that supports your Linux distribution.

OmniSharp provides a richer C# editing experience, with features like IntelliSense and Find All References.
It is recommend that you download the version of OmniSharp that runs on Mono using the following steps:
    1. If it's not already installed, download and install Mono (https://www.mono-project.com)
    2. Download and untar the latest OmniSharp Mono release from  https://github.com/OmniSharp/omnisharp-roslyn/releases/
    3. In Visual Studio Code, select Preferences->User Settings to open settings.json.
    4. In settings.json, add a new setting: "omnisharp.path": "/path/to/omnisharp/OmniSharp.exe"
    5. In settings.json, add a new setting: "omnisharp.useMono": true
    6. Restart Visual Studio Code.

一、關於 Mono 的安裝

sudo apt-get install mono-complete

算是安裝成功啦。

二、下載 OmniSharp Mono Release

到:https://github.com/OmniSharp/omnisharp-roslyn/releases/ 下載最新的,當前 v1.9-beta14,解壓縮後,放在 ~/.vscode文件夾下

cd ~/.vscode
    mkdir omnisharp
    cd omnisharp
    cp /path/to/omnisharp-mono.tar.gz ./
    tar zxvf omnisharp-mono.tar.gz
    ls

解釋 會在這個文件夾下發現 ~/.vscode/omnisharp/OmniSharp.exe 文件,對就是這個帶 exe 的文件,按照上面的說法,Visual Studio Code, 選擇 Preferences->User Settings 打開 settings.json. 在 settings.json, 加上 "omnisharp.path": "/path/to/omnisharp/OmniSharp.exe" 和"omnisharp.useMono": true

// Place your settings in this file to overwrite the default settings
{
    "omnisharp.path": "/home/litianci/.vscode/omnisharp/OmniSharp.exe",
    "omnisharp.useMono": true
}

解釋

  • 裏面的地址須要根據實際狀況修改。
  • 重啓 vscode.

二、安裝 dnvm, dnv,dnx 等

curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh

安裝好了 dnvm, 須要本身首先安裝 curl

dnvm upgrade -r mono
dnvm upgrade -r coreclr # 先安裝吧,不爲過。
sudo apt-get install mono-complete # 安裝全套,我也不知道須要不須要更多內容
sudo apt-get install libuv1 # 安裝 libuv1

三、使用 vscode 打開上述例子。

這裏再也不廢話,有問題,歡迎下面留言。

5、VSCode 一個複雜的 quizz 例子

代碼複製於 http://download.csdn.net/detail/u013003382/9498661 某章節,下面試着在 deepin 下熟悉 C# 和 ASP.NET core 的通常編寫過程。(待續)

相關文章
相關標籤/搜索