我想创建一个 nuget 包来将 MVC-ish 的库导入到 MVC 项目中。例如:
- 楷模
- 枚举
- 属性
但我对如何包含他们的命名空间感到困惑。
创建新的类库后,我尝试使用 namespace System.ComponentModels.DataAnnotations
,但无法识别。
我尝试使用References
解决方案资源管理器中的部分。但那里似乎没有选择 - 只有消息:
No recent framework assemblies were found on your machine or in your project.json
.
好的,所以我去project.json
文件。
但我不确定我应该如何在这里添加这些引用。
{
"version": "1.0.0-*",
"description": "ClassLibrary1 Class Library",
"authors": [ "MHL" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"System.Collections": "4.0.0.0",
"System.Linq": "4.0.0.0",
"System.Threading": "4.0.0.0",
"System.Runtime": "4.0.0.0",
"Microsoft.CSharp": "4.0.0.0",
"System.ComponentModel.DataAnotations": "4.0.0.0"
},
"frameworks": {
"dotnet": { }
}
}
如果我添加"System.ComponentModel.DataAnotations": "4.0.0.0"
到该dependencies
部分,我会收到 build error Dependency could not be resolved
。
因此,我认为我应该更改该frameworks
部分中的某些内容。
但我不确定要添加什么,尤其是因为有很多选项(例如“dotnet”、“net40”、“net50”、“dnx”等)!
我的理解是,该frameworks
部分使单个 nuget 包能够针对不同的框架版本。但实际上,我想要的只是一个通用的 MVC 包。我不想将包不必要地限制为特定版本的框架。