我有一个.NET Core控制台应用程序并已运行dotnet publish.但是,我无法弄清楚如何从命令行运行应用程序.任何提示?
我们目前正在使用ASP.NET Core重写/转换我们的ASP.NET WebForms应用程序.尽量避免重新设计.
我们HttpContext在类库中使用了一个部分来检查当前状态.如何HttpContext.Current在.NET Core 1.0中访问?
var current = HttpContext.Current;
if (current == null)
{
// do something here
// string connection = Configuration.GetConnectionString("MyDb");
}
Run Code Online (Sandbox Code Playgroud)
我需要访问它才能构建当前的应用程序主机.
$"{current.Request.Url.Scheme}://{current.Request.Url.Host}{(current.Request.Url.Port == 80 ? "" : ":" + current.Request.Url.Port)}";
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用nopCommerce(这是用.NET Core编写的),但当我想运行该项目时,我面临52个错误告诉我运行一个nuget包恢复
资产文件〜\ obj\project.assets.json'找不到.运行NuGet包还原以生成此文件.Nop.Web.MVC.Testsote
当我使用右键单击解决方案并选择Restore Nuget Packages时,我收到以下消息:
所有软件包都已安装,无需恢复.
但那些52个错误仍然存在,并且在工具 - > NuGet包管理器 - >管理NuGet包解决方案中解决方案 没有安装任何东西,我最近也将我的VS2017更新为15.5.4
我正在尝试访问我的 Asp.net core v6 应用程序 Program.cs 文件中的 appsettings.json,但在此版本的 .Net 中,Startup 类和 Program 类合并在一起,并且 using 和 another 语句被简化并从 Program 中删除。CS。在这种情况下,如何访问 IConfiguration 或如何使用依赖注入?
这是 Asp.net 6 为我创建的默认 Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = "localhost:6379";
});
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "BasketAPI", Version = "v1" });
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BasketAPI v1"));
}
app.UseHttpsRedirection(); …Run Code Online (Sandbox Code Playgroud) 我有一个相当奇怪的问题正在发生.
这是我的代码
private async Task BreakExpectedLogic()
{
bool test = false;
if (test == true)
{
Console.WriteLine("Hello!");
throw new Exception("BAD HASH!");
}
}
Run Code Online (Sandbox Code Playgroud)
看起来真的很简单,不应该打Console.WriteLine或者throw.由于某种原因,它总是击中throw.
如果我移动throw到自己的方法然后它工作正常.我的问题是它是如何忽略if阻挡并击中阻挡的throw new Exception
编辑1我已更新我的代码以包含签名,我删除了与此问题无关的所有内容并运行它,它仍然发生
当我PM> Remove-Migration -context BloggingContext使用EF Core在VS2015中运行ASP.NET Core项目时,我收到以下错误:
System.InvalidOperationException: The migration '20160703192724_MyFirstMigration' has already been applied to the database. Unapply it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration. at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsRemoveCommand.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
The migration '20160703192724_MyFirstMigration' has already been applied to the database. Unapply it and try again. If the migration has …Run Code Online (Sandbox Code Playgroud) c# entity-framework-core visual-studio-2015 .net-core asp.net-core
我在本地克隆了ASP.NET Core SignalR Repo,并尝试在以下环境中打开解决方案.
IDE
Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055
Run Code Online (Sandbox Code Playgroud)
DOT NET CLI
? dotnet --info
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
Run Code Online (Sandbox Code Playgroud)
我最终看到了很多这类错误消息:
..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj:error:项目的默认XML名称空间必须是MSBuild XML名称空间.如果项目是以MSBuild 2003格式创作的,请添加xmlns="http://schemas.microsoft.com/developer/msbuild/2003"到元素中.如果项目是以旧的1.0或1.2格式编写的,请将其转换为MSBuild 2003格式...\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj
我想知道如何以正确的方式解决这个问题.
msbuild asp.net-mvc visual-studio-2015 .net-core asp.net-core
.NET Core和ASP.NET Core之间究竟有什么区别?
它们是互相排斥的吗?我听说asp.net核心是基于.net核心构建的,但也可以构建在完整的.net框架上.
那么ASP.NET Core到底是什么?
我在:OSX 10.11.6,Homebrew版本0.9.9m OpenSSL 0.9.8zg 2015年7月14日
我正在尝试使用dotnetcore并遵循他们的指示,
我升级/安装了最新版本的openssl:
> brew install openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2h_1.el_capitan.bottle.tar.gz
Already downloaded: /Users/administrator/Library/Caches/Homebrew/openssl-1.0.2h_1.el_capitan.bottle.tar.gz
==> Pouring openssl-1.0.2h_1.el_capitan.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local.
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences …Run Code Online (Sandbox Code Playgroud) ASP.NET Core支持一个新的配置系统,如下所示:https: //docs.asp.net/en/latest/fundamentals/configuration.html
.NET Core控制台应用程序是否也支持此模型?
如果不是以前app.config和ConfigurationManager型号的替代品?