.net 开发中遇到的一些问题

.Net 开发中遇到的一些坑

1、Asp .net Core 项目打包成 docker 镜像时,出现 ***xx.csproj未找到错误

大概率是因为当前执行的目录不在sln目录,切换到sln目录就可以了

2、编译Docker镜像时,出现 Determining projects to restore... error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json. 但是实际上可以访问 https://api.nuget.org/v3/index.json

大概率是有多个网络连接,禁用那些不能联网的连接。来源

3、使用Visial Studio在Docker中运行Asp.Net Core时,端口总是不固定

在 项目->Properties->launchSettings.json 中配置。
找到 Container (Dockerfile) 配置,新增 "httpPort": {port}, "sslPort": {port} ,httpPort是http端口,sslPort是https端口。

"Container (Dockerfile)": {
     "commandName": "Docker",
     "launchBrowser": true,
     "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
     "environmentVariables": {
         "ASPNETCORE_HTTPS_PORTS": "8081",
         "ASPNETCORE_HTTP_PORTS": "8080"
     },
     "publishAllPorts": true,
     "useSSL": true,
     "httpPort": 5090,
     "sslPort": 5091
 }
posted @ 2024-05-13 08:32  冰冻企鹅  阅读(57)  评论(0)    收藏  举报