附加进程调试
打开项目选择【调试-附加到进程】
(.net framework 要附加到 w3wp.exe,.net core 要附加到 dotnet.exe)
热更新版本bat
@echo off
chcp 65001
# 先根据服务名称删除相关服务
set rootPath=%~1
set serviceName=%~2
taskkill /F /T /FI "WINDOWTITLE eq %serviceName%" /IM dotnet.exe
# 转到服务根目录
cd /d %rootPath%
echo ASPNETCORE_ENVIRONMENT=Development
dotnet build %默认Debug编辑模式./bin/Debug/%
start "%serviceName%" dotnet watch run
exit
断点调试版本bat
@echo off
chcp 65001
set rootPath=%~1
set serviceName=%~2
taskkill /F /T /FI "WINDOWTITLE eq %serviceName%" /IM dotnet.exe
cd /d %rootPath%inDebug
etcoreapp2.1
start "%serviceName%" dotnet %serviceName%.dll
发布版本bat
@echo off
chcp 65001
set rootPath=%~1
set serviceName=%~2
set targetFramework=%~3
taskkill /F /T /FI "WINDOWTITLE eq %serviceName%" /IM dotnet.exe
set COMPILE_PATH=%rootPath%inRelease\%targetFramework%publish
rd "%COMPILE_PATH%" /s/q
cd /d %rootPath%
dotnet publish -c Release
Configuration
静态读取
var demo = this.Configuration.GetSection(nameof(Demo)).Get<Demo>();
Console.WriteLine(demo.ToString());
public void ConfigureServices(IServiceCollection services)
{
services.Configure<Demo>(this.Configuration.GetSection(nameof(Demo)));
}
动态配置
public void ConfigureServices(IServiceCollection services)
{
services.Configure<Demo>(binder=>
{
binder.Property1 = var1;
binder.Property2 = var2;
});
}
// inject
public DemoController(IOptions<Demo> setting)
{
var demo = setting.Value;
}
写文件到指定目录
合适的Exception
ArgumentException
ArgumentNullException
NotImplementedException