【发布时间】:2017-02-08 08:03:11
【问题描述】:
Visual Studio 代码的 c# 扩展中的调试器似乎改变了路由的工作方式;如果我使用 dotnet run 运行应用程序,一切都很好,但如果我使用调试器,某些路由会被忽略。
使用 dotnet run 响应
使用 c# 调试器响应(通过 app.Run(...);)
据我所知,配置中没有任何内容会影响这一点。
程序.cs
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.CaptureStartupErrors(true)
.UseSetting("detailedErrors","true")
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Startup.cs
public class Startup
{
public IConfigurationRoot Configuration { get; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFrameworkSqlServer()
.AddDbContext<MyDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MyDbContext"))
);
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory
.AddDebug()
.AddConsole()
.AddAzureWebAppDiagnostics();
var logger = loggerFactory.CreateLogger<Startup>();
logger.LogInformation(1, "Logging in Configure");
logger.LogInformation(1, $"ConnectionString: {Configuration.GetConnectionString("MyDbContext")}");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvc(routes => {
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
app.Run(async context => {
await context.Response.WriteAsync($"Hello World: The current environment is {env.EnvironmentName}, the current value is {Configuration["MyEnvironment"]}");
});
}
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}\\src\\web\\bin\\Debug\\netcoreapp1.0\\web.dll",
"args": [],
"cwd": "${workspaceRoot}\\src\\web",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}]
}
任何帮助表示赞赏。
【问题讨论】:
标签: c# debugging visual-studio-code asp.net-core-mvc