.net core源码调试前的配置

一直想想研究.net core的源码,参照 solenovex大牛的方法,最后终于成功启动了.net core源码,过程如下:

1、powershell定位到 X:\aspnetcore\eng\scripts,运行其中的InstallVisualStudio.ps1,在弹出的VS修改安装界面后,直接点修改,安装完成后关闭即可。

2、cmd定位到X:\aspnetcore目录下,运行restore.cmd,此时会下载一个目录X:\aspnetcore\.dotnet,关闭cmd窗口停止restore进程,编辑目录下的dotnet-install.ps1文件,

Say "Downloading link: $DownloadLink"
try {
DownloadFile -Source $DownloadLink -OutPath $ZipPath

修改成

Say "Downloading link: $DownloadLink,$ZipPath"
try {
while(![System.IO.File]::Exists($ZipPath)){
Start-Sleep -s 5
}
Say "$ZipPath is has exists"
# DownloadFile -Source $DownloadLink -OutPath $ZipPath

作出上面修改的原因是,powershell可能是单线程下载或网络原因(你懂的),

DownloadFile -Source $DownloadLink -OutPath $ZipPath 这句话是下载安装包 ,我们注释掉它,不让它下载,

Say "Downloading link: $DownloadLink,$ZipPath" 中的$DownloadLink是远程下载地址,$ZipPath是临时文件路径,知道了这两个地址后用循环判断,如果文件不存在就休眠5秒,这时我们可以用多线程下载工具或浏览器下载远程地址的文件,下载完成后复制到临时目录改成$ZipPath的临时文件名,然后线程就会解压文件进行安装,这样就不用等很久才能下载安装包。

3、restore有可能会有些文件没下载会,也可以在cmd下执行build.cmd命令,估计作用和restore.cmd是一样的。

4、成功后还要修改D:\aspnetcore\src\Components\Server\src\Microsoft.AspNetCore.Components.Server.csproj  具体问题看 https://github.com/dotnet/aspnetcore/pull/18713/files/9142fbf5940c4c8cd8cc66f50fe63569f50747e0#diff-8d3e3b66d47490ce28ba798996aea5ec

修改成如下内容,对照修改下面绿色粗体内容

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
    <Description>Runtime server features for ASP.NET Core Components.</Description>
    <IsAspNetCoreApp>true</IsAspNetCoreApp>
    <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <NoWarn>CS0436;$(NoWarn)</NoWarn>
    <DefineConstants>$(DefineConstants);ENABLE_UNSAFE_MSGPACK;SPAN_BUILTIN;MESSAGEPACK_INTERNAL;COMPONENTS_SERVER</DefineConstants>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="Microsoft.AspNetCore.Components.Authorization" />
    <Reference Include="Microsoft.AspNetCore.Components.Web" />
    <Reference Include="Microsoft.AspNetCore.DataProtection.Extensions" />
    <Reference Include="Microsoft.AspNetCore.SignalR" />
    <Reference Include="Microsoft.AspNetCore.StaticFiles" />
    <Reference Include="Microsoft.Extensions.Caching.Memory" />
    <Reference Include="Microsoft.Extensions.FileProviders.Composite" />
    <Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
    <Reference Include="Microsoft.Extensions.Logging" />
    <Reference Include="Microsoft.Extensions.ValueStopwatch.Sources" PrivateAssets="All" />

    <!-- Add a project dependency without reference output assemblies to enforce build order -->
    <!-- Applying workaround for https://github.com/microsoft/msbuild/issues/2661 and https://github.com/dotnet/sdk/issues/952 -->
    <ProjectReference
      Include="..\..\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj"
      ReferenceOutputAssemblies="false"
      SkipGetTargetFrameworkProperties="true"
      UndefineProperties="TargetFramework"
      Private="false"
      Condition="'$(BuildNodeJS)' != 'false' and '$(BuildingInsideVisualStudio)' != 'true'" />
  </ItemGroup>

  <PropertyGroup>
    <MessagePackRoot>$(RepoRoot)src\submodules\MessagePack-CSharp\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\</MessagePackRoot>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="$(ComponentsSharedSourceRoot)src\CacheHeaderSettings.cs" Link="Shared\CacheHeaderSettings.cs" />
    <Compile Include="$(ComponentsSharedSourceRoot)src\ArrayBuilder.cs" LinkBase="Circuits" />
    <Compile Include="$(ComponentsSharedSourceRoot)src\ElementReferenceJsonConverter.cs" />

    <Compile Include="..\..\Shared\src\BrowserNavigationManagerInterop.cs" />
    <Compile Include="..\..\Shared\src\JsonSerializerOptionsProvider.cs" />
    <Compile Include="..\..\Shared\src\WebEventData.cs" />

    <Compile Include="$(RepoRoot)src\SignalR\common\Shared\BinaryMessageFormatter.cs" LinkBase="BlazorPack" />
    <Compile Include="$(RepoRoot)src\SignalR\common\Shared\BinaryMessageParser.cs" LinkBase="BlazorPack" />
    <Compile Include="$(RepoRoot)src\SignalR\common\Shared\MemoryBufferWriter.cs" LinkBase="BlazorPack" />

    <!-- MessagePack -->
    <Compile Include="$(MessagePackRoot)BufferWriter.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)ExtensionHeader.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)ExtensionResult.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)MessagePackCode.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)MessagePackReader.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)T4\MessagePackReader.Integers.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)MessagePackSerializationException.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)MessagePackWriter.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)Nil.cs" LinkBase="BlazorPack\MessagePack" />
    <!--<Compile Include="$(MessagePackRoot)FloatBits.cs" LinkBase="BlazorPack\MessagePack" />-->
    <Compile Include="$(MessagePackRoot)Internal\DateTimeConstants.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)StringEncoding.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)SequencePool.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)SequenceReader.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)SequenceReaderExtensions.cs" LinkBase="BlazorPack\MessagePack" />
    <Compile Include="$(MessagePackRoot)Utilities.cs" LinkBase="BlazorPack\MessagePack" />

    <!-- Shared descriptor infrastructure with MVC -->
    <Compile Include="$(RepoRoot)src\Shared\Components\ServerComponent.cs" />
    <Compile Include="$(RepoRoot)src\Shared\Components\ComponentParameter.cs" />
    <Compile Include="$(RepoRoot)src\Shared\Components\ServerComponentSerializationSettings.cs" />
    <Compile Include="$(RepoRoot)src\Shared\Components\ServerComponentMarker.cs" />
  </ItemGroup>

  <PropertyGroup>
    <BlazorServerJSFile>..\..\Web.JS\dist\$(Configuration)\blazor.server.js</BlazorServerJSFile>
  </PropertyGroup>

  <ItemGroup>
    <EmbeddedResource Include="$(BlazorServerJSFile)" LogicalName="_framework/%(Filename)%(Extension)" />
    <EmbeddedResource Include="$(BlazorServerJSFile).map" LogicalName="_framework/%(Filename)%(Extension)" Condition="Exists('$(BlazorServerJSFile).map')" />
  </ItemGroup>

</Project>
 
5、这时可以打开 其中的源码解决方案,比如 X:\aspnetcore\src\Mvc ,双击这个目录下的startvs.cmd ,会调用VS打开 MVC.sln并还原依赖的包,直接打开MVC.sln好像无法加载项目,我以后再试。
6、如果正常打开项目,可以试着生成解决方案,如果生成成功,那么调试就没问题了。默认是test目录下的BasicWebSite项目为启动项目的,你也可以修改其它项目为启动项目。
7、.net core源码调试成功,记下解决经历以备忘也可以帮助到其他的人。
posted @ 2020-05-05 12:59  编程-一生坚持的事业  阅读(815)  评论(3编辑  收藏  举报