公司一个项目要从.net framework平台转成.net core平台,都是为了跨平台啊。 老的项目中用了个小众的类库:DapperExtensions。 有个同事直接nuget安装了该类库的.net core版本:DapperExtensions.NetCore,然后一直报错;于是向我求助。 报错代码如下图: 报错信息: P.S 同事用的是异步调用,同步调用是没问题的。 由于此类库不再更新,官网也没有了……也找不到文档; 在网上很少的资料中,都是些简单的示例,使用的都是同步调用,但同事用的是异步调用。我们一块折腾了半个上午,也没解决。但还不想放弃啊……于是又双叒叕重新撸了n遍,豁然发现:生成的MySQL语句里怎么会有中括号!灯下黑~…… 于是,网上一通搜,终于找到一篇说SQL方言的文档,看了一下DapperExtensions的源码,发现也有设置SQL方言的方法:
1 |
DapperExtensions.DapperExtensions.SqlDialect = new MySqlDialect(); |
运行……还是报错……%~@#¥,没起作用!无奈……拉倒吧,把代码改为同步调用吧。 还是不想放弃,再看一眼吧——竟然发现DapperExtensions的源码中异步方法和同步方法的SQL方言竟然是单独设置的,这类库设计的也没谁了……,于是设置了一下异步的SQL方言为MySQL,终于解决了。代码如下:
1 |
DapperExtensions.DapperAsyncExtensions.SqlDialect = new MySqlDialect(); |
总结: 不要使用小众类库,尤其是个人开发的。因为出了问题太难解决了。 解决问题要细心,更要有耐心;放空思想,从头多撸几遍。 小众类库的代码设计考虑不周: a. 比如说,代码已经写为new MySqlConnection(ConnString),SQL方言就应该自动设置为MySQL了。 b. 另一个,对于SQL方言,设置一次就行了,不应该设计成异步要单独设置。 解决过程实属不易,希望能帮助大家,谢谢~
View Details
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public class UnixDateTimeConvertor : DateTimeConverterBase { public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return DateTime.Parse(reader.Value.ToString()); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { //System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); //long timeStamp = (long)(((DateTime)value) - startTime).TotalMilliseconds; writer.WriteValue(((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss")); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API 配置和服务 //GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new IsoDateTimeConverter //{ // DateTimeFormat = "yyyy-MM-dd HH:mm:ss" //}); // Web API 路由 config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); //设置Datetime 到 時間戳 的互轉 JsonSerializerSettings jSettings = new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Formatting.Indented, DateTimeZoneHandling = DateTimeZoneHandling.Local }; jSettings.Converters.Add(new UnixDateTimeConvertor()); config.Formatters.JsonFormatter.SerializerSettings = jSettings; } } |
from:https://www.cnblogs.com/liuqiyun/p/10729338.html
View Details一、创建.net core web api 的Demo 修改部分代码 端口随意指定,ip用星号“*”,方便接下来docker虚拟网络自动分配ip 下一步是Dockerfile文件,如果发现你的项目中没有此文件,很简单,右键项目=》添加=》Docker支持即可,然后修改文件如下图 然后发布项目并上传文件到服务器 二、将api项目部署到docker中 首先,进入到你上传的文件目录 根据目录下的Dockerfile创建镜像:docker build -t dockerapitestimage . (注意,注意,注意后面有一个点“.”,看清楚了,这个点表示当前目录上下文) 如果你在这一步失败了,请先尝试在docker下拉取dotnet镜像,执行命令 docker pull dotnet:latest ,拉取完之后再创建api镜像 这里要下载好几百兆的镜像包,网速太慢的话,建议尝试阿里云镜像加速,具体见我另外一篇文章 docker使用阿里云镜像加速 镜像创建成功后,我们就可以来创建容器并使用啦,继续往下 可以看到服务已经成功启动了,接下来准备访问一下试试 在linux中,首先我们输入$ docker ps 看下详情,如下图 发现我们的dockerapitest容器的ip地址是 0.0.0.0:8001,接着在linux中访问看看,成功了 linux下都没问题了,然后我们回windows下看看,如下图,显然成功了。 from:https://www.cnblogs.com/luoocean/p/11100684.html
View Details问题 模型验证无效时,没有进入到接口里,而是直接报400 Bad Request,非常不友好。 环境 SDK:.Net Core 2.2.401 开发工具:VS2017 step 1 创建接口
1 2 3 4 5 6 7 8 9 10 11 |
/// <summary> /// 注册 /// </summary> /// <param name="input">request Body</param> [HttpPost] [AllowAnonymous] public object PostRegister([FromBody] InputUserRegister input) { var userService = GetService<IUserService>(); return userService.Register(input); } |
Step 2 创建模型 引用命名空间
1 |
using System.ComponentModel.DataAnnotations; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class InputUserRegister { [Required(ErrorMessage = "请填写用户名")] [StringLength(20, ErrorMessage = "用户名长度过长")] public string UserName { get; set; } [Required(ErrorMessage = "请填写密码")] [StringLength(20, ErrorMessage = "密码长度过长")] public string Password { get; set; } [Required(ErrorMessage = "请填写确认密码")] [Compare("Password", ErrorMessage = "两次输入的密码不一致")] public string ConfirmPassword { get; set; } } |
Step 3 测试 解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#region 禁止默认行为 services.Configure<ApiBehaviorOptions>(options => { options.InvalidModelStateResponseFactory = (context) => { if (context.ModelState.IsValid) return null; var error = ""; foreach (var item in context.ModelState) { var state = item.Value; var message = state.Errors.FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.ErrorMessage))?.ErrorMessage; if (string.IsNullOrWhiteSpace(message)) { message = state.Errors.FirstOrDefault(o => o.Exception != null)?.Exception.Message; } if (string.IsNullOrWhiteSpace(message)) continue; error = message; break; } return new JsonResult(new Models.VModels.ErrorResponse(error.ToString())); }; }); #endregion |
from:https://www.cnblogs.com/EminemJK/p/11498852.html
View Details一般的我们可以直接使用参数来接受,这个就不多介绍了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[HttpGet] public IHttpActionResult Test2([FromUri]string name) { object obj = new { name = "sss", age = 78, sex = true }; return Ok(new { errcode = 0, data = obj }); } [HttpPost] public IHttpActionResult Test3([FromBody]string name) { throw new Exception("嘻嘻嘻"); } /// <summary> /// 返回强类型 /// </summary> /// <param name="name"></param> /// <returns></returns> [HttpGet] public CommonOutDto Test4([FromUri]string name) { CommonOutDto outDto = new CommonOutDto(); outDto.errcode = 0; return outDto; } |
现在一般使用json来传递参数,如果使用强类型,需要我们把类的属性和参数名设置一样就可以了。get,post都可以,这里只演示了post请求 ①使用参数名来接受,这样显示不管你是传递json字符串还是json对象都是接收不到的
1 2 3 4 5 |
[HttpPost] public IHttpActionResult Test4([FromBody]string json) { throw new Exception("嘻嘻嘻"); } |
②稍微改动下,把参数类型换成objct,这样我们不管是传递json对象和字符串都是能够接受到的
1 2 3 4 5 |
[HttpPost] public IHttpActionResult Test4([FromBody]object json) { throw new Exception("嘻嘻嘻"); } |
json对象; json字符串: 正解:普通的两种使用方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/// <summary> /// 如果没有定义Dto类型 /// </summary> /// <param name="json">json数据</param> /// <returns></returns> [HttpPost] public IHttpActionResult Test3([FromBody]object json) { JObject @object = JObject.Parse(json.ToString()); return Ok(@object); } /// <summary> /// 定义了Dto类型 /// </summary> /// <param name="inDto"> /// 根据json 定义的类 /// </param> /// <returns></returns> [HttpPost] public IHttpActionResult Test4(ToiletInfoInDto inDto) { // CommonOutDto 为自定义的返回类 CommonOutDto outDto = new CommonOutDto(); outDto.dataStr = "请求成功"; outDto.errcode = 0; return Ok(outDto); } |
1 |
ToiletInfoInDto : |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/// <summary> /// 厕所信息 /// </summary> public class ToiletInfoInDto { /// <summary> /// 厕所编号 /// </summary> public string CsNum { get; set; } /// <summary> /// 厕所名称 /// </summary> public string CsName { get; set; } /// <summary> /// 百度经度 /// </summary> public string CoordX { get; set; } /// <summary> /// 百度纬度 /// </summary> public string CoordY { get; set; } /// <summary> /// 厕所等级 /// </summary> public string Rank { get; set; } } |
1 |
CommonOutDto: |
1 2 3 4 5 6 7 8 9 10 11 |
/// <summary> /// 返回公共类 /// </summary> public class CommonOutDto { public int errcode { get; set; } public string dataStr { get; set; } public string errmsgStr { get; set; } } |
③mvc中也可以写接口,我们肯定使用过流接受过参数,那webapi中同样是可以的 mvc中可以直接写:
1 |
string json2 = new StreamReader(Request.InputStream).ReadToEnd(); |
webapi中没有 HttpContext这个,我们可以引用进行使用
1 2 |
//引用 using System.Web; string json2 = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd(); |
webapi中我们使用request强制同步获取数据,显示获取不到
1 2 |
//强制同步获取不到数据 string aa = this.Request.Content.ReadAsStringAsync().GetAwaiter().GetResult(); |
推荐:使用异步的方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/// <summary> /// 使用objct接受 /// </summary> /// <param name="json"></param> /// <returns></returns> [HttpPost] public async Task<IHttpActionResult> TestAsync([FromBody]object json) { JObject @object = JObject.Parse(json.ToString()); return await Task.FromResult<IHttpActionResult>(Ok(@object)); } /// <summary> /// 使用强类型接受 /// </summary> /// <param name="inDto"></param> /// <returns></returns> [HttpPost] public async Task<IHttpActionResult> TestAsync2(ToiletInfoInDto inDto) { return await Task.FromResult<IHttpActionResult>(Ok(inDto)); } /// <summary> /// 使用读取数据的方式 /// </summary> /// <returns></returns> [HttpPost] public async Task<IHttpActionResult> TestAsync3() { string aa = await this.Request.Content.ReadAsStringAsync(); return await Task.FromResult<IHttpActionResult>(Ok(aa)); } /// <summary> /// 使用强类型接受,返回强类型 推荐这种,输入,输出都新建一个对应的Dto进行处理 /// </summary> /// <param name="inDto">输入类</param> /// <returns>输出类</returns> [HttpPost] public async Task<CommonOutDto> TestAsync4(ToiletInfoInDto inDto) { CommonOutDto outDto = new CommonOutDto(); outDto.errcode = 0; return await Task.FromResult(outDto); } |
显示结果:
1 |
可以看到我们的 TestAsync2 接口中,我们的属性小写了,这是自己序列化json数据造成的,俗称:驼峰式。 当然这个是可以设置的,我们在webapiConfig.cs 中可以设置我们的json的属性 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API 配置和服务 // Web API 路由 config.MapHttpAttributeRoutes(); //多添加一个action config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); // 干掉XML序列化器 两种都可以 //GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); config.Formatters.Remove(config.Formatters.XmlFormatter); //配置json数据格式 JsonMediaTypeFormatter jsonFormatter = config.Formatters.JsonFormatter; //忽略循环引用,如果设置为Error,则遇到循环引用的时候报错(建议设置为Error,这样更规范) jsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Error; //日期格式化,默认的格式也不好看 jsonFormatter.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; // 对 JSON 数据使用混合大小写。跟属性名同样的大小.输出 jsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver(); //json中属性开头字母小写的驼峰命名 //jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); } } |
总结: 1:一般的我们使用Object类型或者强类型来接接收 2:提高效率,我们是异步 题外:我们一般都会准备一个Dto来接受我们的json对象,如果你不想这样写,也可以使用JObject来用。 from:https://www.cnblogs.com/Sea1ee/p/10438838.html
View Details本教程演示如何在 Docker 容器中运行 ASP.NET Core 应用。 在本教程中,你将了解: 了解 Microsoft.NET 核心 Docker 映像 下载 ASP.NET Core 示例应用 本地运行示例应用 在 Linux 容器中运行示例应用 在 Windows 容器中运行示例应用 手动生成和部署 ASP.NET Core Docker 映像 在本教程中,你下载 ASP.NET Core 示例应用并在 Docker 容器中运行它。 此示例适用于 Linux 和 Windows 容器。 示例 Dockerfile 使用 Docker 多阶段构建功能在不同的容器中生成和运行。 生成和运行容器是由 Microsoft 从 Docker 中心提供的映像中创建的: dotnet/core/sdk 此示例将此映像用于生成应用。 此映像包含带有命令行工具 (CLI) 的 .NET Core SDK。 此映像对本地开发、调试和单元测试进行了优化。 为开发和编译而安装的工具使其成为一个相对较大的映像。 dotnet/core/aspnet 此示例将此映像用于运行应用。 此映像包含 ASP.NET Core 运行时和库,并针对在生产中运行应用进行了优化。 此映像专为部署和应用启动的速度而设计,相对较小,因此优化了从 Docker 注册表到 Docker 主机的网络性能。 仅将运行应用所需的二进制文件和内容复制到容器。 已准备运行内容,以此实现从 Docker run 到应用启动的最快时间。 Docker 模型中不需要动态代码编译。 先决条件 .NET Core SDK 3.0 Docker 客户端 18.03 或更高版本 Linux 分布 CentOS Debian Fedora Ubuntu macOS Windows Git 下载示例应用 通过克隆 .NET Core Docker 存储库下载示例: 控制台复制 […]
View Details
1 2 3 4 5 6 |
========== 正在准备容器 ========== 正在准备 Docker 容器... C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File "C:\Users\MESTC\AppData\Local\Temp\GetVsDbg.ps1" -Version vs2017u5 -RuntimeID linux-x64 -InstallPath "C:\Users\MESTC\vsdbg\vs2017u5" Info: Using vsdbg version '16.0.20412.1' Info: Using Runtime ID 'linux-x64' Info: C:\Users\MESTC\vsdbg\vs2017u5 exists, deleting. |
如上情况 感兴趣可以打开 GetVsDbg.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# Copyright (c) Microsoft. All rights reserved. <# .SYNOPSIS Downloads the given $Version of vsdbg for the given $RuntimeID and installs it to the given $InstallPath .DESCRIPTION The following script will download vsdbg and install vsdbg, the .NET Core Debugger .PARAMETER Version Specifies the version of vsdbg to install. Can be 'latest', 'vs2019', 'vs2017u5', 'vs2017u1', or a specific version string i.e. 15.0.25930.0 .PARAMETER RuntimeID Specifies the .NET Runtime ID of the vsdbg that will be downloaded. Example: linux-x64. Defaults to win7-x64. .Parameter InstallPath Specifies the path where vsdbg will be installed. Defaults to the directory containing this script. .INPUTS None. You cannot pipe inputs to GetVsDbg. .EXAMPLE C:\PS> .\GetVsDbg.ps1 -Version latest -RuntimeID linux-x64 -InstallPath .\vsdbg .LINK For more information about using this script with Visual Studio Code see: https://github.com/OmniSharp/omnisharp-vscode/wiki/Attaching-to-remote-processes For more information about using this script with Visual Studio see: https://github.com/Microsoft/MIEngine/wiki/Offroad-Debugging-of-.NET-Core-on-Linux---OSX-from-Visual-Studio To report issues, see: https://github.com/omnisharp/omnisharp-vscode/issues #> Param ( [Parameter(Mandatory=$true, ParameterSetName="ByName")] [string] [ValidateSet("latest", "vs2019", "vs2017u1", "vs2017u5")] $Version, [Parameter(Mandatory=$true, ParameterSetName="ByNumber")] [string] [ValidatePattern("\d+\.\d+\.\d+.*")] $VersionNumber, [Parameter(Mandatory=$false)] [string] $RuntimeID, [Parameter(Mandatory=$false)] [string] $InstallPath = (Split-Path -Path $MyInvocation.MyCommand.Definition) ) $ErrorActionPreference="Stop" # In a separate method to prevent locking zip files. function DownloadAndExtract([string]$url, [string]$targetLocation) { Add-Type -assembly "System.IO.Compression.FileSystem" Add-Type -assembly "System.IO.Compression" [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Try { $zipStream = (New-Object System.Net.WebClient).OpenRead($url) } Catch { Write-Host "Info: Opening stream failed, trying again with proxy settings." $proxy = [System.Net.WebRequest]::GetSystemWebProxy() $proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials $webClient = New-Object System.Net.WebClient $webClient.UseDefaultCredentials = $false $webClient.proxy = $proxy $zipStream = $webClient.OpenRead($url) } $zipArchive = New-Object System.IO.Compression.ZipArchive -ArgumentList $zipStream [System.IO.Compression.ZipFileExtensions]::ExtractToDirectory($zipArchive, $targetLocation) $zipArchive.Dispose() $zipStream.Dispose() } # Checks if the existing version is the latest version. function IsLatest([string]$installationPath, [string]$runtimeId, [string]$version) { $SuccessRidFile = Join-Path -Path $installationPath -ChildPath "success_rid.txt" if (Test-Path $SuccessRidFile) { $LastRid = Get-Content -Path $SuccessRidFile if ($LastRid -ne $runtimeId) { return $false } } else { return $false } $SuccessVersionFile = Join-Path -Path $installationPath -ChildPath "success_version.txt" if (Test-Path $SuccessVersionFile) { $LastVersion = Get-Content -Path $SuccessVersionFile if ($LastVersion -ne $version) { return $false } } else { return $false } return $true } function WriteSuccessInfo([string]$installationPath, [string]$runtimeId, [string]$version) { $SuccessRidFile = Join-Path -Path $installationPath -ChildPath "success_rid.txt" $runtimeId | Out-File -Encoding utf8 $SuccessRidFile $SuccessVersionFile = Join-Path -Path $installationPath -ChildPath "success_version.txt" $version | Out-File -Encoding utf8 $SuccessVersionFile } $ExplitVersionNumberUsed = $false if ($Version -eq "latest") { $VersionNumber = "16.0.20412.1" } elseif ($Version -eq "vs2019") { $VersionNumber = "16.0.20412.1" } elseif ($Version -eq "vs2017u5") { $VersionNumber = "16.0.20412.1" } elseif ($Version -eq "vs2017u1") { $VersionNumber = "15.1.10630.1" } else { $ExplitVersionNumberUsed = $true } Write-Host "Info: Using vsdbg version '$VersionNumber'" if (-not $RuntimeID) { $RuntimeID = "win7-x64" } elseif (-not $ExplitVersionNumberUsed) { $legacyLinuxRuntimeIds = @{ "debian.8-x64" = ""; "rhel.7.2-x64" = ""; "centos.7-x64" = ""; "fedora.23-x64" = ""; "opensuse.13.2-x64" = ""; "ubuntu.14.04-x64" = ""; "ubuntu.16.04-x64" = ""; "ubuntu.16.10-x64" = ""; "fedora.24-x64" = ""; "opensuse.42.1-x64" = ""; } # Remap the old distro-specific runtime ids unless the caller specified an exact build number. # We don't do this in the exact build number case so that old builds can be used. if ($legacyLinuxRuntimeIds.ContainsKey($RuntimeID.ToLowerInvariant())) { $RuntimeID = "linux-x64" } } Write-Host "Info: Using Runtime ID '$RuntimeID'" # if we were given a relative path, assume its relative to the script directory and create an absolute path if (-not([System.IO.Path]::IsPathRooted($InstallPath))) { $InstallPath = Join-Path -Path (Split-Path -Path $MyInvocation.MyCommand.Definition) -ChildPath $InstallPath } if (IsLatest $InstallPath $RuntimeID $VersionNumber) { Write-Host "Info: Latest version of VsDbg is present. Skipping downloads" } else { if (Test-Path $InstallPath) { Write-Host "Info: $InstallPath exists, deleting." Remove-Item $InstallPath -Force -Recurse -ErrorAction Stop } $target = ("vsdbg-" + $VersionNumber).Replace('.','-') + "/vsdbg-" + $RuntimeID + ".zip" $url = "https://vsdebugger.azureedge.net/" + $target DownloadAndExtract $url $InstallPath WriteSuccessInfo $InstallPath $RuntimeID $VersionNumber Write-Host "Info: Successfully installed vsdbg at '$InstallPath'" } |
1 2 3 4 5 6 |
========== 正在准备容器 ========== 正在准备 Docker 容器... C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File "C:\Users\MESTC\AppData\Local\Temp\GetVsDbg.ps1" -Version vs2017u5 -RuntimeID linux-x64 -InstallPath "C:\Users\MESTC\vsdbg\vs2017u5" Info: Using vsdbg version '16.0.20412.1' Info: Using Runtime ID 'linux-x64' Info: C:\Users\MESTC\vsdbg\vs2017u5 exists, deleting. |
下面说说解决方案 下载包
1 |
https://vsdebugger.azureedge.net/vsdbg-(你的版本号.号换成-号)/vsdbg-(你的Runtime ID).zip |
1 |
例如我的 |
1 2 3 |
https://vsdebugger.azureedge.net/vsdbg-16-0-20412-1/vsdbg-linux-x64.zip 下载之后解压到你的安装路径 例如我的 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
-InstallPath "C:\Users\MESTC\vsdbg\vs2017u5" 然后在该文件下添加一个<em>success_rid.txt文件,内容为</em>你的Runtime ID 例如我的linux-x64 还要添加一个success_version.txt文件,内容为你的版本号,如16.0.20412.1 重启 visual studio 下面还会下载另一个,相同的处理方式,再重启一次就ok了 最新版操作过程 最新下载文件路径 https://vsdebugger.azureedge.net/vsdbg-16-2-10709-2/vsdbg-linux-x64.zip https://vsdebugger.azureedge.net/vsdbg-16-2-10709-2/vsdbg-linux-musl-x64.zip 解压路径 |
1 |
C:\Users\用户名\vsdbg\vs2017u5 -> vsdbg-linux-x64.zip |
1 2 3 4 |
C:\Users\用户名\vsdbg\vs2017u5\linux-musl-x64 -> vsdbg-linux-musl-x64.zip 解压完了,在路径 C:\Users\用户名\vsdbg\vs2017u5 里面 新建 <em>success_rid.txt 编辑内容 </em>linux-x64,再新建 success_version.txt <em>编辑内容 16.2.10709.2 </em> |
1 |
在路径 C:\Users\用户名\vsdbg\vs2017u5\linux-musl-x64 里面 新建 <em>success_rid.txt 编辑内容 </em>linux-musl-x64,再新建 success_version.txt <em>编辑内容 16.2.10709.2<br>完成</em> |
转载于:https://www.cnblogs.com/microestc/p/10784877.html from:https://blog.csdn.net/weixin_30809333/article/details/99176681
View Details工具VS2019 MSDN解决方法:https://docs.microsoft.com/zh-cn/visualstudio/containers/troubleshooting-docker-errors?view=vs-2019 执行net localgroup docker-users DOMAIN\username(“DOMAIN\username”这个是用户名,根据你的电脑的用户名填入) /add from:https://blog.csdn.net/weixin_41432198/article/details/104575932
View Details未启用卷共享。 启用“Docker CE for Windows”设置中的卷共享(仅 Linux 容器) 若要解决此问题,请执行以下操作: 右键单击通知区域中的“Docker for Windows” ,并选择“设置” 。 选择“共享驱动器” ,并共享系统驱动器和项目所在的驱动器。 备注 如果文件显示“已共享”,可能仍需要单击对话框底部的“重置凭据…”链接,以便重新启用卷共享。 若要在重置凭据后继续,可能必须重启 Visual Studio。 提示 如果未配置共享驱动器,Visual Studio 2017 版本 15.6 之后的版本会发出提示 。 容器类型 向项目添加 Docker 支持后,请选择 Windows 或 Linux 容器。 Docker 主机必须运行类型相同的容器。 要更改正在运行的 Docker 实例中的容器类型,请右键单击系统托盘中的 Docker 图标,再选择“切换到 Windows 容器…”或“切换到 Linux 容器…” 。 无法开始调试 其中一个原因可能与在用户配置文件的文件夹中有过时调试组件有关。 请执行以下命令来删除这些文件夹,以便在下次调试会话上下载最新调试组件。 del %userprofile%\vsdbg del %userprofile%\onecoremsvsmon 调试应用程序时特定于网络的错误 尝试执行可从清理容器主机网络下载的脚本,此操作会刷新主机上的网络相关组件。 装载被拒绝 使用 Docker for macOS 时,可能会遇到引用文件夹 /usr/local/share/dotnet/sdk/NuGetFallbackFolder 错误。 将文件夹添加到 Docker 中的“文件共享”选项卡 Docker 用户组 使用容器时,可能会在 Visual Studio 中遇到以下错误: 复制
1 2 3 |
The current user must be in the 'docker-users' group to use Docker Desktop. Add yourself to the 'docker-users' group and then log out of Windows. |
必须是“docker-users”组的成员,才有使用 Docker 容器的权限。 若要将自己添加到 Windows 10 中的组,请执行以下步骤: 从“开始”菜单中,打开“计算机管理” 。 展开“本地用户和组”,并选择“组” 。 找到“docker-users”组,右键单击并选择“添加到组” 。 添加用户帐户或帐户。 注销后再次登录,以使更改生效。 还可以在管理员命令提示符下使用 net localgroup 命令向特定组添加用户。 cmd复制
1 2 |
<span class="hljs-built_in">net</span> localgroup docker-users DOMAIN\username /add |
[…]
View DetailsAsp.Net Core 提供内置的日志,支持依赖注入,可以很方便地在控制器、Razor页面一级ViewComponent中使用。不过缺省提供的Provider只包括向控制台、Debug输出、Event Log等的输出,没有将日志记录到文件的缺省Provider,当然可以使用Log4Net等第三方日志插件,不过感觉太重了,最近发现了一个轻量级的日志插件,只需要一行代码的配置,就可以实现将日志输出到文件。首先,使用NuGet增加包 Serilog.Extensions.Logging.File到项目中,然后,在StartUp->Configure中增加如下设置
1 2 3 4 |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddFile("Logs/PlatCore-{Date}.txt"); } |
配置就完成了,由于实现了ILogger接口,因此使用方法与缺省的完全相同。在项目的Logs文件夹中,可以查看输出的日志文件。 作者:寻找无名的特质 链接:https://www.jianshu.com/p/fb7f064223f7 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
View Details