XUCore.Template.WeChat 7.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet new install XUCore.Template.WeChat::7.0.7                
This package contains a .NET Template Package you can call from the shell/command line.

XUCore.Template.WeChat

XUCore.Template.WeChat

基于 FreeSql 的精简分层快速开发项目模板,生成 Web WeChat 项目

使用模板

本地安装模板:可详情见 install-template.bat 文件内

本地安装模板步骤

如果已经装过旧版,可以先执行下面命令进行卸载:


dotnet new -u xwechat

然后安装指定版本:


dotnet new --install XUCore.Template.WeChat::{version}

创建项目

切换到指定创建的目录。

假设我们需要在 E:\demo 创建,

那么先切换到该目录


cd E:\demo

然后执行下面命令创建项目


dotnet new xwechat -n MyTest -o .

这里的 xwechat 是使用模板短名称。

MyTest 为新创建的项目名称。

avatar

本地构建项目镜像到 Docker(如果使用 jenkins 可以直接在 jenkins 里配置)

前提是 dockerfile 需要放在项目根目录,而非启动项目的目录

不采用微软自带的 dockerfile,我们需要手工打包发布。

1、切换到项目目录


cd E:\demo\MyTest.WebApi2

2、本地编译


dotnet build -c Release

3、本地发布(实际发布到当前项目的 bin/Release/net5.0/publish/ 目录)


dotnet publish -c Release

4、打包进 docker


docker build -t mytest:0.0.1 .

从控制台中,我们可以看到打包过程


E:\MyTest>docker build -t mytest:0.0.1 .
[+] Building 14.7s (12/20)
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0                                                  0.0s
[+] Building 15.1s (12/20)
 => [internal] load build definition from Dockerfile                                                               0.0s
[+] Building 30.4s (12/20)
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
[+] Building 56.7s (21/21) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0                                                  0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:5.0                                               0.0s
 => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:5.0                                                              0.0s
 => [internal] load build context                                                                                  1.2s
 => => transferring context: 119.91MB                                                                              1.2s
 => [base 1/5] FROM mcr.microsoft.com/dotnet/aspnet:5.0                                                            0.0s
 => CACHED [build 2/7] WORKDIR /src                                                                                0.0s
 => CACHED [build 3/7] COPY [MyTest.WebApi2/MyTest.WebApi2.csproj, MyTest.WebApi2/]                                   0.0s
 => CACHED [build 4/7] RUN dotnet restore "MyTest.WebApi2/MyTest.WebApi2.csproj"                                     0.0s
 => [build 5/7] COPY . .                                                                                           0.4s
 => [build 6/7] WORKDIR /src/MyTest.WebApi2                                                                         0.0s
 => [build 7/7] RUN dotnet build "MyTest.WebApi2.csproj" -c Release -o /app/build                                  43.2s
 => [publish 1/1] RUN dotnet publish "MyTest.WebApi2.csproj" -c Release -o /app/publish                            11.5s
 => CACHED [base 2/5] ADD [sources.list, /etc/apt/]                                                                0.0s
 => CACHED [base 3/5] RUN rm /etc/localtime                                                                        0.0s
 => CACHED [base 4/5] RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime                                   0.0s
 => CACHED [base 5/5] WORKDIR /app                                                                                 0.0s
 => CACHED [final 1/2] WORKDIR /app                                                                                0.0s
 => CACHED [final 2/2] COPY --from=publish /app/publish .                                                          0.0s
 => exporting to image                                                                                             0.0s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:addb11051debc4cf74c7d048d15cafdb7edbf121ae54fc55960f1b46bce94fda                       0.0s
 => => naming to docker.io/library/mytest:0.0.1                                                                    0.0s
 => => #   Determining projects to restore...
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

结束后,我们使用 docker images 查看打包好的镜像


E:\MyTest>docker images
REPOSITORY                        TAG       IMAGE ID       CREATED        SIZE
mytest                            0.0.1     addb11051deb   20 hours ago   258MB
mcr.microsoft.com/dotnet/sdk      5.0       1cfcb8589c29   12 days ago    631MB
mcr.microsoft.com/dotnet/aspnet   5.0       592a912e0dcb   12 days ago    205MB

3、启动容器


docker run --name my-test -d -p 8090:8090 mytest:0.0.1

启动后我们通过 docker ps -a 查看运行的镜像


E:\MyTest>docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS                       PORTS     NAMES
35c9010404ae   mytest:0.0.1   "dotnet MyTest.WebAp…"   5 minutes ago   Exited (139) 4 minutes ago             my-test

4、浏览器访问

http://127.0.0.1:8090/swagger

此时容器会报错,因为在创建项目后配置文件内需要修改数据库连接地址(进入容器后,我们的所有数据库地址以及其他相关地址都需要修改为内网访问,或者公网访问)

我们可以查看容器的日志,方便我们定位错误


docker logs 35c9010404ae

此时,在容器日志,我们看到


fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
      An error occurred using the connection to database '' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]

客户端接入 API


API 隐藏操作说明
head value 说明
limit-mode contain or ignore contain 的意思是指定输出字段, ignore 的意思是忽略指定字段
limit-field 字段集合 指定要输出或要忽略的字段,以英文逗号分隔,如:column1,column2,column3
limit-field-rename 要重命名的字段 字段以输出为准,比如:code=c,subCode=sub,data=data,nickname=userNickName
limit-resolver camelcase or default camelcase 的意思是指定输出小驼峰字段, default 的意思是默认输出大小写字段
limit-date-unix true or false 当设置为true的时候 则是所有DateTime时间全部返回时间戳,当为false的时候不启用
limit-date-format 日期格式化字符串 比如:yyyy-MM-dd'T'HH:mm:ss'Z' 返回的数据如:2021-01-06T10:03:38Z
1、如何改变 DateTime 的格式?

我们需要在 http 请求的时候,在 head 里加入配置

head value 说明
limit-date-unix true or false 当设置为true的时候 则是所有DateTime时间全部返回时间戳,当为false的时候不启用
limit-date-format 日期格式化字符串 比如:yyyy-MM-dd'T'HH:mm:ss'Z' 返回的数据如:2021-01-06T10:03:38Z

注意: limit-date-unix的优先级要大于limit-date-format


2、如何重命名和指定输出需要的字段?
head value 说明
limit-mode contain or ignore contain 的意思是指定输出字段, ignore 的意思是忽略指定字段
limit-field 字段集合 指定要输出或要忽略的字段,以英文逗号分隔,如:column1,column2,column3
limit-field-rename 要重命名的字段 字段以输出为准,比如:code=c,subCode=sub,data=data,nickname=userNickName

注意:当你使用重命名limit-field-rename字段后,指定输出的字段limit-field要以重命名后的字段名为准,大小写也请依照你重命名后的格式。

任何指定输出,均不影响原始定义的结构。

3、如何指定输出小驼峰字段?
head value 说明
limit-resolver camelcase or default camelcase 的意思是指定输出小驼峰字段, default 的意思是默认输出大小写字段

任何指定输出,均不影响原始定义的结构。

示例一

如下表设置:

设置 说明
limit-mode contain 指定匹配输出模式
limit-field code,subCode,data,userId,userNickName,entName 设置需要的字段集合,英文逗号分隔

示例二

如下表设置:

设置 说明
limit-mode contain 指定匹配输出模式
limit-field code,sub,data,totalPages,totalRecords,pageDatas,createTime,nickName,entId,entName 设置需要的字段集合,英文逗号分隔,并以重命名后的字段为准设置输出字段
limit-field-rename subcode=sub,data=data,items=pageDatas,userNickName=nickName 重命名字段

示例三

如下表设置:

设置 说明
limit-mode ignore 指定忽略输出模式
limit-field code,subCode,message,userId,userNickName,entName,productType,userHeadImg_48 设置要忽略的字段集合,英文逗号分隔

示例四

如下表设置:

设置 说明
limit-mode ignore 指定忽略输出模式
limit-field code,subCode,message,userId,userNickName,entName,productType,userHeadImg_48 设置要忽略的字段集合,英文逗号分隔
limit-date-unix true 设置 DateTime 输出时间戳
Accept application/json 指定输出 json 格式的 json 字符串格式

适用范围定义

在一定程度上使 API 接入变得稍微复杂了一点点,但是能优化网络传输,或许我们可以考虑牺牲一点复杂度,按需索取来优化传输问题。

客户端 适合程度
移动端 非常适合
web 端 适合
服务端 跨语言,在不同规范的情况下适合接入,能解决模型不一致的问题,k8s 内走内网地址不需要考虑这个问题
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.1 5,929 12/5/2023 8.0.1 is deprecated because it is no longer maintained and has critical bugs.
7.7.8 2,368 11/9/2023 7.7.8 is deprecated because it is no longer maintained and has critical bugs.
7.7.7 2,458 11/8/2023 7.7.7 is deprecated because it is no longer maintained and has critical bugs.
7.7.6 2,834 11/8/2023 7.7.6 is deprecated because it is no longer maintained and has critical bugs.
7.7.5 2,639 11/7/2023 7.7.5 is deprecated because it is no longer maintained and has critical bugs.
7.7.4 2,775 11/7/2023 7.7.4 is deprecated because it is no longer maintained and has critical bugs.
7.7.3 2,688 11/7/2023 7.7.3 is deprecated because it is no longer maintained and has critical bugs.
7.7.2 2,504 11/7/2023 7.7.2 is deprecated because it is no longer maintained and has critical bugs.
7.7.1 2,758 11/7/2023 7.7.1 is deprecated because it is no longer maintained and has critical bugs.
7.7.0 2,797 11/3/2023 7.7.0 is deprecated because it is no longer maintained and has critical bugs.
7.6.9 2,820 11/3/2023 7.6.9 is deprecated because it is no longer maintained and has critical bugs.
7.6.8 2,755 11/3/2023 7.6.8 is deprecated because it is no longer maintained and has critical bugs.
7.6.7 2,765 11/3/2023 7.6.7 is deprecated because it is no longer maintained and has critical bugs.
7.6.6 2,772 11/2/2023 7.6.6 is deprecated because it is no longer maintained and has critical bugs.
7.6.5 2,825 10/31/2023 7.6.5 is deprecated because it is no longer maintained and has critical bugs.
7.6.4 2,772 10/31/2023 7.6.4 is deprecated because it is no longer maintained and has critical bugs.
7.6.3 2,574 10/30/2023 7.6.3 is deprecated because it is no longer maintained and has critical bugs.
7.6.2 2,606 10/27/2023 7.6.2 is deprecated because it is no longer maintained and has critical bugs.
7.6.1 2,714 10/27/2023 7.6.1 is deprecated because it is no longer maintained and has critical bugs.
7.6.0 2,856 10/27/2023 7.6.0 is deprecated because it is no longer maintained and has critical bugs.
7.5.9 2,338 10/27/2023 7.5.9 is deprecated because it is no longer maintained and has critical bugs.
7.5.8 2,962 10/27/2023 7.5.8 is deprecated because it is no longer maintained and has critical bugs.
7.5.7 2,888 10/26/2023 7.5.7 is deprecated because it is no longer maintained and has critical bugs.
7.5.6 2,794 10/26/2023 7.5.6 is deprecated because it is no longer maintained and has critical bugs.
7.5.5 2,789 10/26/2023 7.5.5 is deprecated because it is no longer maintained and has critical bugs.
7.5.4 2,600 10/26/2023 7.5.4 is deprecated because it is no longer maintained and has critical bugs.
7.5.3 2,427 10/25/2023 7.5.3 is deprecated because it is no longer maintained and has critical bugs.
7.5.2 2,903 10/25/2023 7.5.2 is deprecated because it is no longer maintained and has critical bugs.
7.5.1 2,876 10/25/2023 7.5.1 is deprecated because it is no longer maintained and has critical bugs.
7.5.0 2,871 10/24/2023 7.5.0 is deprecated because it is no longer maintained and has critical bugs.
7.4.9 2,936 10/24/2023 7.4.9 is deprecated because it is no longer maintained and has critical bugs.
7.4.8 2,770 10/24/2023 7.4.8 is deprecated because it is no longer maintained and has critical bugs.
7.4.7 2,672 10/23/2023 7.4.7 is deprecated because it is no longer maintained and has critical bugs.
7.4.6 2,759 10/20/2023 7.4.6 is deprecated because it is no longer maintained and has critical bugs.
7.4.5 2,770 10/20/2023 7.4.5 is deprecated because it is no longer maintained and has critical bugs.
7.4.4 2,840 10/18/2023 7.4.4 is deprecated because it is no longer maintained and has critical bugs.
7.4.3 3,056 10/9/2023 7.4.3 is deprecated because it is no longer maintained and has critical bugs.
7.4.2 2,896 10/8/2023 7.4.2 is deprecated because it is no longer maintained and has critical bugs.
7.4.1 2,750 10/7/2023 7.4.1 is deprecated because it is no longer maintained and has critical bugs.
7.4.0 2,884 9/15/2023 7.4.0 is deprecated because it is no longer maintained and has critical bugs.
7.3.9 3,028 9/15/2023 7.3.9 is deprecated because it is no longer maintained and has critical bugs.
7.3.8 2,778 9/14/2023 7.3.8 is deprecated because it is no longer maintained and has critical bugs.
7.3.7 2,810 9/14/2023 7.3.7 is deprecated because it is no longer maintained and has critical bugs.
7.3.6 2,941 9/14/2023 7.3.6 is deprecated because it is no longer maintained and has critical bugs.
7.3.5 3,033 9/13/2023 7.3.5 is deprecated because it is no longer maintained and has critical bugs.
7.3.4 2,432 9/13/2023 7.3.4 is deprecated because it is no longer maintained and has critical bugs.
7.3.3 2,557 9/13/2023 7.3.3 is deprecated because it is no longer maintained and has critical bugs.
7.3.2 2,803 9/12/2023 7.3.2 is deprecated because it is no longer maintained and has critical bugs.
7.3.1 2,872 9/12/2023 7.3.1 is deprecated because it is no longer maintained and has critical bugs.
7.3.0 2,770 9/12/2023 7.3.0 is deprecated because it is no longer maintained and has critical bugs.
7.2.9 3,233 9/7/2023 7.2.9 is deprecated because it is no longer maintained and has critical bugs.
7.2.8 2,704 9/7/2023 7.2.8 is deprecated because it is no longer maintained and has critical bugs.
7.2.7 3,047 9/6/2023 7.2.7 is deprecated because it is no longer maintained and has critical bugs.
7.2.6 2,620 9/6/2023 7.2.6 is deprecated because it is no longer maintained and has critical bugs.
7.2.5 2,902 9/6/2023 7.2.5 is deprecated because it is no longer maintained and has critical bugs.
7.2.4 2,898 8/31/2023 7.2.4 is deprecated because it is no longer maintained and has critical bugs.
7.2.3 2,762 8/31/2023 7.2.3 is deprecated because it is no longer maintained and has critical bugs.
7.2.2 3,057 8/30/2023 7.2.2 is deprecated because it is no longer maintained and has critical bugs.
7.2.1 2,794 8/30/2023 7.2.1 is deprecated because it is no longer maintained and has critical bugs.
7.2.0 2,965 8/30/2023 7.2.0 is deprecated because it is no longer maintained and has critical bugs.
7.1.9 2,768 8/29/2023 7.1.9 is deprecated because it is no longer maintained and has critical bugs.
7.1.8 2,925 8/29/2023 7.1.8 is deprecated because it is no longer maintained and has critical bugs.
7.1.7 3,108 8/29/2023 7.1.7 is deprecated because it is no longer maintained and has critical bugs.
7.1.6 2,732 8/29/2023 7.1.6 is deprecated because it is no longer maintained and has critical bugs.
7.1.5 3,328 8/28/2023 7.1.5 is deprecated because it is no longer maintained and has critical bugs.
7.1.4 2,831 8/28/2023 7.1.4 is deprecated because it is no longer maintained and has critical bugs.
7.1.3 2,732 8/28/2023 7.1.3 is deprecated because it is no longer maintained and has critical bugs.
7.1.2 2,887 8/25/2023 7.1.2 is deprecated because it is no longer maintained and has critical bugs.
7.1.1 2,865 8/25/2023 7.1.1 is deprecated because it is no longer maintained and has critical bugs.
7.1.0 3,271 8/25/2023 7.1.0 is deprecated because it is no longer maintained and has critical bugs.
7.0.9 2,748 8/25/2023 7.0.9 is deprecated because it is no longer maintained and has critical bugs.
7.0.8 2,492 8/24/2023 7.0.8 is deprecated because it is no longer maintained and has critical bugs.
7.0.7 3,238 8/24/2023 7.0.7 is deprecated because it is no longer maintained and has critical bugs.
7.0.6 2,803 8/24/2023 7.0.6 is deprecated because it is no longer maintained and has critical bugs.
7.0.5 3,047 8/24/2023 7.0.5 is deprecated because it is no longer maintained and has critical bugs.
7.0.4 2,719 8/23/2023 7.0.4 is deprecated because it is no longer maintained and has critical bugs.
7.0.3 2,937 8/23/2023 7.0.3 is deprecated because it is no longer maintained and has critical bugs.
7.0.2 2,797 8/23/2023 7.0.2 is deprecated because it is no longer maintained and has critical bugs.
7.0.1 2,929 8/23/2023 7.0.1 is deprecated because it is no longer maintained and has critical bugs.
7.0.0 2,816 8/22/2023 7.0.0 is deprecated because it is no longer maintained and has critical bugs.
6.9.18 2,707 8/22/2023 6.9.18 is deprecated because it is no longer maintained and has critical bugs.
6.9.17 2,821 8/22/2023 6.9.17 is deprecated because it is no longer maintained and has critical bugs.
6.9.16 2,976 8/22/2023 6.9.16 is deprecated because it is no longer maintained and has critical bugs.
6.9.15 3,218 8/22/2023 6.9.15 is deprecated because it is no longer maintained and has critical bugs.
6.9.14 2,956 8/22/2023 6.9.14 is deprecated because it is no longer maintained and has critical bugs.
6.9.13 2,661 8/22/2023 6.9.13 is deprecated because it is no longer maintained and has critical bugs.
6.9.12 2,742 8/20/2023 6.9.12 is deprecated because it is no longer maintained and has critical bugs.
6.9.11 2,627 8/19/2023 6.9.11 is deprecated because it is no longer maintained and has critical bugs.
6.9.10 2,910 8/19/2023 6.9.10 is deprecated because it is no longer maintained and has critical bugs.
6.9.9 2,870 8/19/2023 6.9.9 is deprecated because it is no longer maintained and has critical bugs.