考虑到我已经使用.NET Core Web应用程序配置了EF:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(...));
Run Code Online (Sandbox Code Playgroud)
我也可以下载一个包来支持例如SQLite:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(...));
Run Code Online (Sandbox Code Playgroud)
我们如何允许用户在应用安装上"选择"提供商?我的意思是 - 例如,在WordPress中,您可以从下拉列表中进行选择.
这在.NET Core中是否可行?我看到的唯一方法是仅重启应用程序...
最近,我使用 .NET Core Preview 4 SDK 安装了 VS 2017 RC。在新的SDK中,没有project.json
,只有csproj
文件:
<PropertyGroup>
<OutputType>winexe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup
Run Code Online (Sandbox Code Playgroud)
问题是现在是dotnet publish
输出dll
,而不是exe
文件。我尝试过跑步dotnet publish -r win10-x64
,但它甚至无法编译。
如何在 dotnet 1.1 Preview 中制作独立的应用程序?也许我应该runtime
在 csproj 中指定部分(就像 json 中所要求的那样)?
考虑我有以下 json:
{ "version": "1.0" }
Run Code Online (Sandbox Code Playgroud)
我可以将其解析为动态 JObject 并使用:
dynamic result = JObject.Parse(myJson);
string verison = result.Version; //works <3
Run Code Online (Sandbox Code Playgroud)
但服务器返回以下json
{ { "version": "1.0" } }
Run Code Online (Sandbox Code Playgroud)
newtonsoft 认为此 json 有效,但无法再访问版本:
dynamic result = JObject.Parse(myJson);
string verison = result.Version; //error
Run Code Online (Sandbox Code Playgroud)
Version
onltdynamicresult
可用时如何访问?
我有以下.NET Core项目project.json
:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了nuget包(见postcompile
上文)并在nuget中发布.
然后我创建了标准的4.6.2库,但是无法安装包 - 有一个错误,包不包含目标.NET Framework 4.6.2的有效程序集.
我应该如何准备nuget包以使其在标准库中可用?我认为目标NETStandard对核心项目和标准项目都有效.
我有一个提供文件的动作:
public ActionResult() GetFile
{
return this.File("C:\\test.txt", "text/plain",
"test.txt");
}
Run Code Online (Sandbox Code Playgroud)
但是动作会导致错误:
FileNotFoundException:找不到文件:C:\ test.txt Microsoft.AspNetCore.Mvc.Internal.VirtualFileResultExecutor + d__4.MoveNext()
我确定文件exstis - 它可以通过"运行"窗口(Win + R)打开.为什么Asp.net核心mvc没有"看到"该文件?