下载、编译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 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

下载、编译AspNetCore 的全过程

上一篇:面试题 01.03. URL化


下一篇:如何将站点从http升级到https以保障访问安全