【发布时间】:2015-11-18 18:40:28
【问题描述】:
我想创建一个 nuget 包来将 MVC 风格的库导入到 MVC 项目中。例如:
- 型号
- 枚举
- 属性
但我对如何包含它们的命名空间感到困惑。
新建类库后,我尝试使用命名空间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 部分,我会收到构建错误Dependency could not be resolved。
所以我认为我应该更改frameworks 部分中的某些内容。
但我不确定要添加什么,尤其是因为选项太多(例如“dotnet”、“net40”、“net50”、“dnx”等)!
我的理解是frameworks 部分使单个 nuget 包能够针对不同的框架版本。但实际上,我想要的只是一个通用的 MVC 包。我不想将包不必要地限制为特定版本的框架。
【问题讨论】:
标签: c# asp.net-mvc nuget nuget-package nuget-spec