.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源碼調試成功,記下解決經歷以備忘也可以幫助到其他的人。


免責聲明!

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



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