.net core 项目一键生成脚本
@echo off
echo #-------------------------------------------
echo # ZJCX project-builder for dotnet core
echo # author:cuiguoliang
echo # email:63354361@qq.com
echo # version:1.0
echo # -------------------------------------------
echo 欢迎使用.net core 生成工具by 老亮!
pause
set /p projName=请输入项目名称(默认:LaoLiang.Test):;
if "%projName%"=="" (
set projName=LaoLiang.Test
)
echo 开始生成项目...
set folder=%projName%.Service
set slnName=%folder%.sln
set modelName=%projName%.Models
set dalName=%projName%.DAL
set bllName=%projName%.BLL
set apiName=%projName%.API
set commonName=%projName%.Common
dotnet new sln -o %folder% && cd %folder%
dotnet new classlib -o %modelName%
dotnet new classlib -o %dalName%
dotnet new classlib -o %bllName%
dotnet new classlib -o %commonName%
dotnet new webapi -o %apiName%
echo 添加解决方案关联关系
set apiProj=%apiName%/%apiName%.csproj
dotnet sln %slnName% add %modelName%/%modelName%.csproj
dotnet sln %slnName% add %dalName%/%dalName%.csproj
dotnet sln %slnName% add %bllName%/%bllName%.csproj
dotnet sln %slnName% add %apiProj%
dotnet sln %slnName% add %commonName%/%commonName%.csproj
echo 删除无用类文件
del /f /s /q Class1.cs
echo 添加类库关联关系
dotnet add %apiProj% reference %bllName%/%bllName%.csproj
dotnet add %apiProj% reference %commonName%/%commonName%.csproj
dotnet add %apiProj% reference %modelName%/%modelName%.csproj
dotnet add %dalName%/%dalName%.csproj reference %modelName%/%modelName%.csproj
dotnet add %bllName%/%bllName%.csproj reference %modelName%/%modelName%.csproj
dotnet add %bllName%/%bllName%.csproj reference %dalName%/%dalName%.csproj
echo API添加Nuget类库
:dotnet add %apiProj% package Newtonsoft.Json
:dotnet add %apiProj% package StyleCop.Analyzers
:dotnet add %apiProj% package ZJCX.Log -f netstandard2.0
:dotnet add %apiProj% package ZJCX.IdGenerate -f netstandard2.0
:dotnet add %apiProj% package ZJCX.WebAPI.Connect -f netstandard2.0
echo 添加三方类库
echo 添加其他依赖
echo 还原项目依赖
dotnet restore
echo 项目生成完毕...
另存 ProjectBuilder.bat
放到指定目录 打开命令提示符输入 ProjectBuilder.bat 【项目名称】
如下输出
F:\Project\Liang\Test\vscode\TTTTT>projbuilder.bat ccc.ppp #------------------------------------------- # ZJCX project-builder for dotnet core # author:cuiguoliang # email:63354361@qq.com # version:1.0 # ------------------------------------------- 请按任意键继续. . . The template "Solution File" was created successfully. The template "Class library" was created successfully. Processing post-creation actions... Running 'dotnet restore' on ccc.ppp.Models\ccc.ppp.Models.csproj... F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.Models\ccc.ppp.Models.csproj 的还原在 122.17 ms 内完成。 Restore succeeded. The template "Class library" was created successfully. Processing post-creation actions... Running 'dotnet restore' on ccc.ppp.DAL\ccc.ppp.DAL.csproj... F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.DAL\ccc.ppp.DAL.csproj 的还原在 123.91 ms 内完成。 Restore succeeded. The template "Class library" was created successfully. Processing post-creation actions... Running 'dotnet restore' on ccc.ppp.BLL\ccc.ppp.BLL.csproj... F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.BLL\ccc.ppp.BLL.csproj 的还原在 123.6 ms 内完成。 Restore succeeded. The template "Class library" was created successfully. Processing post-creation actions... Running 'dotnet restore' on ccc.ppp.Common\ccc.ppp.Common.csproj... F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.Common\ccc.ppp.Common.csproj 的还原在 142.89 ms 内完成。 Restore succeeded. The template "ASP.NET Core Web API" was created successfully. Processing post-creation actions... Running 'dotnet restore' on ccc.ppp.API\ccc.ppp.API.csproj... F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的还原在 84.85 ms 内完成。 Restore succeeded. 已将项目“ccc.ppp.Models\ccc.ppp.Models.csproj”添加到解决方案中。 已将项目“ccc.ppp.DAL\ccc.ppp.DAL.csproj”添加到解决方案中。 已将项目“ccc.ppp.BLL\ccc.ppp.BLL.csproj”添加到解决方案中。 已将项目“ccc.ppp.API\ccc.ppp.API.csproj”添加到解决方案中。 已将项目“ccc.ppp.Common\ccc.ppp.Common.csproj”添加到解决方案中。 已将引用“..\ccc.ppp.BLL\ccc.ppp.BLL.csproj”添加到项目。 已将引用“..\ccc.ppp.Common\ccc.ppp.Common.csproj”添加到项目。 已将引用“..\ccc.ppp.Models\ccc.ppp.Models.csproj”添加到项目。 已将引用“..\ccc.ppp.Models\ccc.ppp.Models.csproj”添加到项目。 已将引用“..\ccc.ppp.Models\ccc.ppp.Models.csproj”添加到项目。 已将引用“..\ccc.ppp.DAL\ccc.ppp.DAL.csproj”添加到项目。 Writing C:\Users\PC-020\AppData\Local\Temp\tmpF903.tmp info : 正在将包“Newtonsoft.Json”的 PackageReference 添加到项目“ccc.ppp.API/ccc.ppp.API.csproj”。 info : 正在还原 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的包... info : GET http://10.1.11.144:9001/nuget/FindPackagesById()?id='Newtonsoft.Json'&semVerLevel=2.0.0 info : GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json info : OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json 368 毫秒 info : OK http://10.1.11.144:9001/nuget/FindPackagesById()?id='Newtonsoft.Json'&semVerLevel=2.0.0 2267 毫秒 info : 包“Newtonsoft.Json”与项目“ccc.ppp.API/ccc.ppp.API.csproj”中指定的所有框架均兼容。 info : 包“Newtonsoft.Json”(版本为 12.0.3)的 PackageReference 已添加到文件“F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj”。 info : 正在提交还原... info : 将资产文件写入磁盘。路径: F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\obj\project.assets.json log : F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的还原在 2.5 sec 内完成。 Writing C:\Users\PC-020\AppData\Local\Temp\tmpC4C.tmp info : 正在将包“StyleCop.Analyzers”的 PackageReference 添加到项目“ccc.ppp.API/ccc.ppp.API.csproj”。 info : 正在还原 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的包... info : GET http://10.1.11.144:9001/nuget/FindPackagesById()?id='StyleCop.Analyzers'&semVerLevel=2.0.0 info : OK http://10.1.11.144:9001/nuget/FindPackagesById()?id='StyleCop.Analyzers'&semVerLevel=2.0.0 77 毫秒 info : GET https://api.nuget.org/v3-flatcontainer/stylecop.analyzers/index.json info : OK https://api.nuget.org/v3-flatcontainer/stylecop.analyzers/index.json 697 毫秒 info : GET https://api.nuget.org/v3-flatcontainer/stylecop.analyzers/1.1.118/stylecop.analyzers.1.1.118.nupkg info : OK https://api.nuget.org/v3-flatcontainer/stylecop.analyzers/1.1.118/stylecop.analyzers.1.1.118.nupkg 763 毫秒 info : 正在安装 StyleCop.Analyzers 1.1.118。 info : 包“StyleCop.Analyzers”与项目“ccc.ppp.API/ccc.ppp.API.csproj”中指定的所有框架均兼容。 info : 包“StyleCop.Analyzers”(版本为 1.1.118)的 PackageReference 已添加到文件“F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj”。 info : 正在提交还原... info : 正在生成 MSBuild 文件 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\obj\ccc.ppp.API.csproj.nuget.g.props。 info : 将资产文件写入磁盘。路径: F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\obj\project.assets.json log : F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的还原在 2.04 sec 内完成。 Writing C:\Users\PC-020\AppData\Local\Temp\tmp1A56.tmp info : 正在将包“ZJCX.Log”的 PackageReference 添加到项目“ccc.ppp.API/ccc.ppp.API.csproj”。 info : 正在还原 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的包... error: 包“ZJCX.Log”与项目“ccc.ppp.API/ccc.ppp.API.csproj”中的“指定的用户”框架不兼容。 Writing C:\Users\PC-020\AppData\Local\Temp\tmp1FD4.tmp info : 正在将包“ZJCX.IdGenerate”的 PackageReference 添加到项目“ccc.ppp.API/ccc.ppp.API.csproj”。 info : 正在还原 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的包... error: 包“ZJCX.IdGenerate”与项目“ccc.ppp.API/ccc.ppp.API.csproj”中的“指定的用户”框架不兼容。 Writing C:\Users\PC-020\AppData\Local\Temp\tmp2533.tmp info : 正在将包“ZJCX.WebAPI.Connect”的 PackageReference 添加到项目“ccc.ppp.API/ccc.ppp.API.csproj”。 info : 正在还原 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的包... error: 包“ZJCX.WebAPI.Connect”与项目“ccc.ppp.API/ccc.ppp.API.csproj”中的“指定的用户”框架不兼容。 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.Common\ccc.ppp.Common.csproj 的还原在 43.03 ms 内完成。 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.Models\ccc.ppp.Models.csproj 的还原在 7.6 ms 内完成。 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.BLL\ccc.ppp.BLL.csproj 的还原在 129.75 ms 内完成。 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.API\ccc.ppp.API.csproj 的还原在 129.75 ms 内完成。 F:\Project\Liang\Test\vscode\TTTTT\ccc.ppp.Service\ccc.ppp.DAL\ccc.ppp.DAL.csproj 的还原在 129.75 ms 内完成。
生成项目结构截图

项目之间的依赖也就填好了,请盆友们们多多指点。
学习完毕!

浙公网安备 33010602011771号