using 引入的不一致 (大小寫、拼字)。MyLib) → 確定。using MyLib.Namespace; (確認大小寫)。// 專案 A: MyLib
namespace MyLib.Models {
public class User {
public string Name { get; set; }
}
}
// 專案 B: WebApp
using MyLib.Models; // 引入命名空間
public class HomeController : Controller {
public ActionResult Index() {
User u = new User { Name = "Tom" }; // 正常使用
return View(u);
}
}
若多個方案共用同一類別庫,建議將目標專案打包為 NuGet 套件 (內建 dotnet pack 或 nuget pack),發布至私有 NuGet Server (Azure Artifacts, MyGet, 本地資料夾),其他專案透過 Install-Package MyLib 參考,享受版本管理與還原自動化。