前言,
1.你看到這篇文章的時候,如果你還沒嘗試過生成源代碼,你可以先試着按照自己的絲路來搞一遍.這樣更好一點.
因為直接給你一個已經運行成功的范本,但是我沒有具體來說我其中的坑.,
最終你可能也會運行成功,但是一些解題的思路可能沒有增加.
就是你雖然解決了問題,但是解決問題的能力沒有提升.
2.看了這篇文章你也不一定能生成成功,有沒有幫助在看具體情況吧...
我的基本環境配置
[
"系統":"Windows 10 專業版",
"Visual Studio":"Visual Studio 2019",
]
從Github源代碼克隆到本地
Github源地址
https://github.com/dotnet/extensions
先Fork到自己的倉庫中,會不會更好點?
將這個項目Fork到自己的庫中,這樣就可以修改完提交到本地庫了.
"Fork your own copy of dotnet/extionsions to your account."
Git命令
git clone --recursive https://github.com/dotnet/extensions.git
看下最終到本地的樣子
克隆到本地上根目錄大概是這個樣子.
切換源代碼分支
先查看下Tag
git tag
如果Tag太多的話,輸入":q"可以返回.
切換分支
git checkout v3.1.0
查看項目里面自帶的文檔
{README.md}
其實這是一個項目的概覽,
對於此次生成並沒有太大幫助.
但是作為一個好習慣,還是先看下這個文檔.
{.\docs\BuildFromSource.md}
我覺得這個是此次生成過程中的重點.必看.
Building Extensions on Windows requires:
- Windows 7 or higher
- At least 5 GB of disk space and a good internet connection
(our build scripts >download a lot of tools and dependencies)- Visual Studio 2019. https://visualstudio.com
- Git. https://git-scm.org
Building in Visual Studio
Visual Studio requires special tools and command lien parameters.
You can acquire these by executing the following on command-line:
.\restore.cmd
.\startvs.cmd
This will download required tools and start Visual Studio
with the correct environment variables.
備注:執行上面的2個命令,可是費勁不少...
{restore.cmd}&{startvs.cmd}命令如果卡在下載sdk階段.
每次執行命令,
都會提示:
.NET Core has not yet been instanlled .Running restore.cmd to install it.
dotnet-install:Downloading link : https://dotnetcli.azureedge.net/dotnet/Sdk/3.1.301/dotnet-sdk-3.1.301-win-x64.zip
我用命令"dotnet --list-sdks"之后發現明明已經安裝了Sdk了.
因為命令一直執行不成功,卡在下載SDK那里,
反正項目怎么都運行不起來,
那幾天這個問題不解決總感覺像塊石頭壓在心里,
關鍵網絡上資源比較少,最后實在頂不住了,
抱着試試的態度,
用我簡陋的English去Git.Issues上提了一個問題.
問題意思大概就是,明明系統中已經安裝了Sdk了,
為什么還要下載這個Sdk?
這里貼一下,熱心人士給出的推理和建議.
startvs.cmd checks to see if there is already a local dotnet installation,
relative to where this repo is checked out on your box.
If you just check out this repo and run startvs.cmd,
it will install dotnet in a folder named .dotnet relative to the repo root - it doesn't care about the global dotnet installation on your machine.
If you run restore.cmd then startvs.cmd,
then startvs shouldn't need to install dotnet again.
最終意思大概是要在項目根目錄下的子目錄{.dotnet}下應該有這個Sdk,
我就將這個鏈接https://dotnetcli.azureedge.net/dotnet/Sdk/3.1.301/dotnet-sdk-3.1.301-win-x64.zip自己先下載下來,
然后解壓縮,放到根目錄的{.dotnet}目錄下.
然后再次還原了項目,竟然就可以了.
最終這兩個命令順利執行成功
.\restore.cmd
.\startvs.cmd
運行該解決方案.
Visual Studio報錯
Detailed Information:
無法找到 .NET Core SDK。請檢查確保已安裝此項且 global.json 中指定的版本(如有)與所安裝的版本相匹配。
cmd命令下和global.json中{Sdks}版本對比下
dotnet --info
將{global.json}中的Sdks版本改成"3.1.301"
終於生成不報錯了.
遺留問題:還有1個未解決的問題.依賴項.黃色感嘆號
這個隨緣吧,以后搜到了原因再說...
我要先看源代碼了...
磕磕絆絆的過程...
看着文章寫得一個步驟一個步驟下來的.
但是誰搞誰知道,沒准哪個步驟就會出現問題,
特別是第一次研究開源項目,更是各種坑.
我剛開始研究開源項目的時候,以為直接下來下來源碼就能生成成功的...
然后各種失敗之后,
去搜索網絡上的教程,知道要先切Git分支,
老老實實去讀各種文檔↓
{README.md}
{/docs/BuildFromSource.md}
特別是上面的都搞定之后,卡在這里好幾天.
.\restore.cmd
.\startvs.cmd
萬事開頭難,但是開始的時候,也是學到最多的時候...