「模组:IDE 参考」修訂間的差異

出自Stardew Valley Wiki
跳至導覽 跳至搜尋
第53行: 第53行:
 
# 打开解决方案资源管理器,如果忘了怎么打开回去看上边的。
 
# 打开解决方案资源管理器,如果忘了怎么打开回去看上边的。
 
# 右键你的项目,选择 '''添加 » 新建项''':<br />[[File:Modding - IDE reference - create file (Visual Studio 1) - ZH.png]]
 
# 右键你的项目,选择 '''添加 » 新建项''':<br />[[File:Modding - IDE reference - create file (Visual Studio 1) - ZH.png]]
# From the 'Add New Item' window, choose the file type (usually ''Visual C# Item » Class''):<br />[[File:Modding - IDE reference - create file (Visual Studio 2).png]]
+
# 在弹出的窗口中选择 '''类''' 文件(位于 '''Visual C# » '''):<br />[[File:Modding - IDE reference - create file (Visual Studio 2) - ZH.png]]
# Enter a descriptive file name and click ''Add'':<br />[[File:Modding - IDE reference - create file (Visual Studio 3).png]]
+
# 输入文件名,这里按照教程流程填写 ModEntry.cs ,然后点击 ''' 添加'''

於 2021年4月14日 (三) 09:39 的修訂

目錄

Robin building.png
“我這裏還有很多事情需要處理。”
— 羅賓

不完整的翻譯

本文或部分尚未完全翻譯成中文。 歡迎您通過編輯幫助其建設。
最後編輯1059 Studio於2021-04-14 09:39:55.

此頁面描述了如何使用 Visual Studio 2019 或 MonoDevelop/Visual Studio for Mac 來製作 SMAPI 模組。參閱在主頁面中的 創建 SMAPI 模組

在你開始之前

  • 安裝 Visual Studio Community (Windows)、MonoDevelop (Linux)、Visual Studio for Mac (Mac)
  • 你應該具備 C# 入門基礎
  • 以下是一些需要記住的基本術語:
    term definition
    IDE 開發環境,就是現在你的 Visual Studio 或 MonoDevelop
    DLL .dll 後綴的文件(全稱叫 動態連結庫,英文 Dynamic Link Library),文件包括了你的代碼,SMAPI 將加載的東西
    項目 每個項目在生成(編譯,或者說是構建)的時候都會生成獨立的文件
    解決方案 項目的集合,每一個工程可以包含多個項目。所謂的工程也稱為解決方案,可以理解為要解決問題的方案,可能聽起來有點奇怪,不過這是專業術語

創建一個模組項目

在編寫模組的代碼之前,需要創建一個解決方案和一個包含它的項目

Windows (Visual Studio 2019)

  1. 打開 Visual Studio 2019.
  2. 點擊 創建新項目
    File:Modding - IDE reference - create project (Visual Studio 1) - ZH.png
  3. 篩選器選擇語言 C#,然後選擇 類庫(.NET Framework),點擊 下一步。確保你選擇了正確的選項,否則是不會起作用的
    File:Modding - IDE reference - create project (Visual Studio 2) - ZH.png
  4. 配置新項目 窗口中:
    1. 輸入你的模組名稱。按照約定,名稱應該是一個由幾個單詞去除空格連起來的字符串(例如 MyNewMod,避免使用特殊字符,如果實在看不習慣可以用下劃線來代替空格。可以使用中文,不過這會讓其他國家的玩家感到困惑,所以為了便於在國際上交流請儘可能避免使用中文)。
    2. 取消勾選 將解決方案和項目放在同一目錄中
    3. 確保選擇的是 .NET Framework 4.5.2
    4. 點擊 創建 來創建項目
    File:Modding - IDE reference - create project (Visual Studio 3) - ZH.png

設置目標框架

目標框架 是代碼使用的 .NET Framework 版本,它會影響運行模組所需的版本。
推薦的目標框架是 .NET Framework 4.5,它是 SMAPI 所使用的框架版本
那為什麼其他地方說推薦 4.5.2 ?,別問,我也不知道為什麼

在 Visual Studio 2019 中

  1. 打開解決方案資源管理器。如果你那沒有,可以從菜單欄的 視圖 » 解決方案資源管理器 打開:
    File:Modding - IDE reference - show solution pane (Visual Studio) - ZH.png
  2. 右鍵你的項目,選擇 屬性,或者你也可以從菜單欄的 項目 » <項目名>屬性 打開
    File:Modding - IDE reference - change target framework (Visual Studio 1) - ZH.png
  3. 應用程式 選項卡,在 目標框架 下拉菜單中選擇 .NET Framework 4.5
    File:Modding - IDE reference - change target framework (Visual Studio 2) - ZH.png
  4. 然後會彈出確認對話框,點擊 確認更改:
    File:Modding - IDE reference - change target framework (Visual Studio 3) - ZH.png

添加文件

在 Visual Studio 2019 中

  1. 打開解決方案資源管理器,如果忘了怎麼打開回去看上邊的。
  2. 右鍵你的項目,選擇 添加 » 新建項
    File:Modding - IDE reference - create file (Visual Studio 1) - ZH.png
  3. 在彈出的窗口中選擇 文件(位於 Visual C# 項 » 類):
    File:Modding - IDE reference - create file (Visual Studio 2) - ZH.png
  4. 輸入文件名,這裏按照教程流程填寫 ModEntry.cs ,然後點擊 添加