• 编译asp.net core源代码,并搭建基于源代码的测试环境


    一、为什么要编译源代码?

      当然是为了进一步深入了解asp.net core,比如我最近对身份认证组件比较感兴趣,网上看了几篇文章没有什么收获的时候,那么直接上源码,进行运行调试。

    学习交流群:307564339

    二、下载apsnetcore源代码

    1.下载到本地

    
    
    #下载项目

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

    # 进入到项目

    cd aspnetcore

    2.查看标签

    git tag
    1.0.0
    .
    .
    .
    v5.0.4

    3.切换到v5.0.2

    git checkout v5.0.2

     4.下载子模块

    git submodule update --init --recursive 

    三、还原和构建

    1.微软构建说明

    请阅读这篇文章查看自己的系统、环境等最低要求

    https://github.com/dotnet/aspnetcore/blob/main/docs/BuildFromSource.md

    2.下载JDK和Node

    1.安装jdk

    https://www.oracle.com/java/technologies/javase-jdk15-downloads.html

    2.设置环境变量

    JAVA_HEOM=C:Program FilesJavajdk-15.0.2

    PAHT=;%JAVA_HOME%in

    3.安装NodeJs

    https://nodejs.org/zh-cn/

    3.安装yarn

    npm install -g yarn 

    4.修改一些项目的编码问题

    打开aspnetcoresrcServersIISIISIntegration.slnf查看警告

    双击警告,把这些文件重新另存为:文件-xxx.cpp另存为-保存(三角箭头)-编码保存-使用Unicode(utf-8带签名的方式保存,不行就换GB2312)

    编译CommonLibTests不保存,大功告成!!!

     修改:aspnetcoresrcRazorRazor estTagHelpersDefaultTagHelperContentTest.cs文件

     修改aspnetcore/eng/Versions.props,去掉版本后面的“servicing.20611.20”

     

     然后重新运行/aspnetcore/build.cmd

    5.下载sdk

    修改/aspnetcore/build.cmd文件

    @ECHO OFF
    SETLOCAL
    PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; try { & '%~dp0build.ps1' %*; exit $LASTEXITCODE } catch { write-host $_; exit 1 }"
    # 在EXIT命令之前加上PAUSE,便于调试
    PAUSE
    SET exit_code=%ERRORLEVEL%
    ECHO build.cmd completed
    EXIT /b %exit_code%

    进入到项目目录以管理员身份运行"aspnetcore/build.cmd"批处理文件

    WARNING: No default group of projects was specified, so building the managed and native projects and their
    dependencies. Run `build.cmd -help` for more details.
    Building of NodeJS projects is disabled since node is not detected on Path and no BuildNodeJs or NoBuildNodeJs setting is set explicitly.
    WARNING: Some managed projects depend on NodeJS projects. Building NodeJS is disabled so the managed projects will
    fallback to using the output from previous builds. The output may not be correct or up to date.
    GET https://dot.net/v1/dotnet-install.ps1
    dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
    dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
    dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
    dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
    
    dotnet-install: Downloading primary link https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.103/dotnet-sdk-5.0.103-win-x64.zip

    会发现代码卡住不动了,因为这个项目是多个小组开发,使用的sdk也有许多,比如java和node环境等等,甚至是不同的sdk版本,我们可以通过复制上面提示的链接进行手动下载

    下载,我这边复制到浏览器发现需要6个小时才能下载好。网速还是不满意的可以采用idm下载器进行下载,我只用了3分钟就下载好了。。。

    在我们运行aspnetcore/build.cmd脚本之后会在项目路径下生成一个.dotnet文件夹,同时在里面生成一个dotnet-install.ps1脚本文件,打开dotnet-install.ps1在643行找到

    DownloadFile函数,修改下面红色的地方

    # $Source:资源路径(可以是网络文件资源,也可以是本地文件资源)
    # $OutPath:输出路径
    function DownloadFile($Source, [string]$OutPath) {
    //新增这样的if,意思是把我们刚才下载好的网络文件,指向我们刚才下载好的本地路径
    if ($Source -eq "https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.103/dotnet-sdk-5.0.103-win-x64.zip") { $Source = "C:UserswangDownloadsCompresseddotnet-sdk-5.0.103-win-x64.zip" } if ($Source -notlike "http*") { # Using System.IO.Path.GetFullPath to get the current directory # does not work in this context - $pwd gives the current directory if (![System.IO.Path]::IsPathRooted($Source)) { $Source = $(Join-Path -Path $pwd -ChildPath $Source) } $Source = Get-Absolute-Path $Source Say "Copying file from $Source to $OutPath" Copy-Item $Source $OutPath return } ..... }

       保存dotnet-install.ps1在次运行build.cmd每次提示:dotnet-install: Downloading primary link https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.103/dotnet-sdk-5.0.103-win-x64.zip

    我们就使用IDM下载这个资源到本地在修改dotnet-install.ps1脚本,把url替换成我们下载好的本地路径,在次运行build.cmd脚本


  • 相关阅读:
    Android图片缩放方法
    网站建设底层知识Socket与Http解析
    802.11成帧封装实现(五)
    802.11成帧封装实现(四)
    802.11成帧封装实现(三)
    802.11成帧封装实现(二)
    802.11成帧封装实现(一)
    802.11n协议解析(二)
    802.11n协议解析(一)
    早期主流的wlan技术(二)
  • 原文地址:https://www.cnblogs.com/chaeyeon/p/14533470.html
Copyright © 2020-2023  润新知