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 的通常编写过程。(待续)

相关文章
相关标签/搜索