ASP.NET 核心 RC2 独立模型以进行跨平台项目
ASP.NET Core RC2 separate models to project for cross-platform
我正在尝试将模型分离到它们自己的项目中,以便在使用新的 .net 核心 class 库的 xamarin 跨平台应用程序中使用。我遇到的问题是:
我的解决方案结构如下:
我的class库project.json如下:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final"
},
"frameworks": {
"net451": { },
"netstandard1.5": {
"imports": [
"dnxcore50",
"portable-net452+win81"
]
},
".netcoreapp1.0": {
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
}
}
我在 Web 应用程序中引用了 class 库,但我不确定我是否正确分离了模型。我试图找到一个解决方案,但因为 ASP.NET 核心框架仍然很新,所以没有太多关于如何将模型分离到它自己的项目中的文档或指南。我希望有人可以提供一些关于如何实现这一目标的指导。
编辑
这是我的 Web 应用程序 project.json:
{
"userSecretsId": "aspnet-Climbing.Web-d856be17-9b54-401e-98b2-4d6589fc7ff3",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
"Climbing.Domain": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
"Microsoft.Extensions.SecretManager.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
},
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
在此先感谢您的帮助。
解决方案中的单个项目并不总是拥有您需要的所有参考资料,您可以像这样手动添加它们。
- 右键单击项目标题。
- 去添加 -> 引用
Screen cap
- Go Assemblies(可能是基于依赖的COM)并选择必要的依赖Screen Cap
听起来好像您没有从 Web 项目到 class 项目的正确引用(或者,您缺少 using
语句。
要从您的 Web 项目引用 class 项目,请更新您的 Web 项目的 project.json
和类似于以下内容的依赖项:
"dependencies": {
"Climing.Domain": {
"version": "1.0.0-*",
"target": "project"
},
}
我发现解决方案很奇怪,它是一个不应该成为问题的命名空间问题。我确信底层 ASP.NET 核心 RC2 框架中某处存在错误,尽管我可能错了?
当我将 class 库中 ApplicationUser 的命名空间从 'Climbing.Web.Models' 更改为 'Climbing.Domain' 时出现问题 - 这是正确的命名空间。一旦我将它改回 'Climbing.Web.Models' 命名空间,问题就解决了。
编辑:
深入研究后发现我没有在引用 ApplicationUser 的视图中更新命名空间。通过更新导入解决了这个问题。
我正在尝试将模型分离到它们自己的项目中,以便在使用新的 .net 核心 class 库的 xamarin 跨平台应用程序中使用。我遇到的问题是:
我的解决方案结构如下:
我的class库project.json如下:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final"
},
"frameworks": {
"net451": { },
"netstandard1.5": {
"imports": [
"dnxcore50",
"portable-net452+win81"
]
},
".netcoreapp1.0": {
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
}
}
我在 Web 应用程序中引用了 class 库,但我不确定我是否正确分离了模型。我试图找到一个解决方案,但因为 ASP.NET 核心框架仍然很新,所以没有太多关于如何将模型分离到它自己的项目中的文档或指南。我希望有人可以提供一些关于如何实现这一目标的指导。
编辑
这是我的 Web 应用程序 project.json:
{
"userSecretsId": "aspnet-Climbing.Web-d856be17-9b54-401e-98b2-4d6589fc7ff3",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
"Climbing.Domain": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
"Microsoft.Extensions.SecretManager.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
},
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
在此先感谢您的帮助。
解决方案中的单个项目并不总是拥有您需要的所有参考资料,您可以像这样手动添加它们。
- 右键单击项目标题。
- 去添加 -> 引用 Screen cap
- Go Assemblies(可能是基于依赖的COM)并选择必要的依赖Screen Cap
听起来好像您没有从 Web 项目到 class 项目的正确引用(或者,您缺少 using
语句。
要从您的 Web 项目引用 class 项目,请更新您的 Web 项目的 project.json
和类似于以下内容的依赖项:
"dependencies": {
"Climing.Domain": {
"version": "1.0.0-*",
"target": "project"
},
}
我发现解决方案很奇怪,它是一个不应该成为问题的命名空间问题。我确信底层 ASP.NET 核心 RC2 框架中某处存在错误,尽管我可能错了?
当我将 class 库中 ApplicationUser 的命名空间从 'Climbing.Web.Models' 更改为 'Climbing.Domain' 时出现问题 - 这是正确的命名空间。一旦我将它改回 'Climbing.Web.Models' 命名空间,问题就解决了。
编辑: 深入研究后发现我没有在引用 ApplicationUser 的视图中更新命名空间。通过更新导入解决了这个问题。