下載、編譯AspNetCore 的全過程


1. clone 源碼

下載新的

git clone --recursive https://github.com/dotnet/aspnetcore

如果之前clone過,但是沒有使用 --recursive參數
可以使用下面命令

git submodule update --init --recursive

git submodule sync --recursive; 
git submodule update --init --force --recursive

注意--recursive是必須的 , 因為: ASP.NET Core uses git submodules to include the source from a few other projects.

2. 切換分支到v3.1.5

git checkout v3.1.5
git checkout -b myV3.1.5

如果git版本>=2.23 , git checkout -b myV3.1.5 這條命令也可以替換為 git switch -c myV3.1.5

3. 編輯項目根目錄的nuget.config

去掉源鏈接中包含"darc-int"的鏈接 (這些是微軟內部的源,外部人員無法使用)
如 下面這些需要去掉:

<add key="darc-int-dotnet-extensions-be18161" value="https://pkgs.dev.azure.com/dnceng/_packaging/darc-int-dotnet-extensions-be18161f/nuget/v3/index.json" /> 
<add key="darc-int-dotnet-efcore-509fe04" value="https://pkgs.dev.azure.com/dnceng/_packaging/darc-int-dotnet-efcore-509fe041/nuget/v3/index.json" /> 
<add key="darc-int-dotnet-core-setup-3acd9b0" value="https://pkgs.dev.azure.com/dnceng/_packaging/darc-int-dotnet-core-setup-3acd9b0c/nuget/v3/index.json" /> 
<add key="darc-int-dotnet-corefx-059a4a1" value="https://pkgs.dev.azure.com/dnceng/_packaging/darc-int-dotnet-corefx-059a4a19/nuget/v3/index.json" /> 
<add key="darc-int-dotnet-aspnetcore-tooling-d63ec4a" value="https://pkgs.dev.azure.com/dnceng/_packaging/darc-int-dotnet-aspnetcore-tooling-d63ec4a1/nuget/v3/index.json" />

4.安裝工具和其他軟件

安裝vs ,即使已經安裝過vs了 ,也推薦執行下面這個腳本。
因為自己安裝的vs可能少安裝一些組件啥的 ;

run eng/scripts/InstallVisualStudio.ps1.

其他需要安裝的還有

  • Git. https://git-scm.org
  • NodeJS. LTS version of 10.14.2 or newer https://nodejs.org.
  • Install yarn globally (npm install -g yarn)
  • Java Development Kit 11 or newer. OpenJDK ,Oracle's JDK 都是可以的
    配置 JAVA_HOME 環境變量 (這里有點不明白了 ,為啥編譯C#需要Java)

5. restore

在powershell中執行 .\restore.cmd ,
這期間還會下載一些壓縮包啥的 ,比較耗時, 注意能否訪問國外網站;

6. build

還是在powershell中執行 .\build.cmd
也會下載東西,比較耗時,但是耗時比restore花費的少一些

7. 在vs中打開項目

使用腳本 .\src\Mvc\startvs.cmd ,打開vs ;
這個腳本設置了一下啟動時需要的變量,推薦使用這個腳本打開vs;

vs啟動后 ,可能會出現加載項目失敗的情況 ,這時找到根目錄的global.json ,修改里面的SDK版本,改成自己電腦上已經安裝的SDK版本;

以我的電腦為例,

C:\Windows\system32>dotnet --info

.NET Core SDK(反映任何 global.json):
 Version:   3.1.301
 Commit:    7feb845744

那么將原來的global.json中的

"sdk": {
    "version": "3.1.103"
  },

改成

"sdk": {
    "version": "3.1.301"
  },

重新加載項目即可 ,另外這里面有個sample ,位置是在: 根目錄\src\Mvc\samples\MvcSandbox


免責聲明!

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



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