bat脚本:生成项目并自动加壳发布
C# 全选
@echo off
:: 参考:https://blog.csdn.net/weixin_41045657/article/details/118058262
:: 设置操作 Build 编译;Clean清理;Rebuild 重新编译详见(https://docs.microsoft.com/zh-cn/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019)
:: 解决方案名称
set slnName="YESWEB.Core.sln"
:: MSBuild.exe程序
set ms="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
set _alllist=(YESWEB.Core,YESWEB.EFCore.BulkExtensions,YESWEB.DB.System,YESWEB.ServerCore,YESWEB.DB.Business,YESWEB.ServerAuthorize,YESWEB.DB.DocNos,YESWEB.ServerLibs,YESWEB.DocNoProvider)
::设置日志等级
::Diagnostic 4 诊断详细级别,它显示所有错误、警告、消息,状态事件以及生成摘要。
::Detailed 3 详情详细级别,它显示 错误、警告、MessageImportance 值为 High 或 Normal 的消息、所有状态事件以及生成摘要。
::Normal 2 普通详细级别,它显示 错误、警告、MessageImportance 值为 High 的消息、一些状态事件以及生成摘要。
::Minimal 1 最小详细级别,它显示 错误、警告、MessageImportance 值为 High 的消息以及生成摘要。
::Quiet 0 静默详细级别,它显示生成摘要。
ECHO 当前VS的版本对应的MSBuild.exe程序路径:%ms%
:OP
@ECHO.
echo 你是否使用这个版本的MSBuild.exe来编译当前程序?如果不需要编译,请关闭此窗口。
echo,&&echo 1:一键 编译,加密,Nuget打包
echo,&&echo 2:Release编译项目
echo,&&echo 3:加密Release dll
echo,&&echo 4:不编译,打包 Nuget
echo,&&echo 5:清理解决方案
echo,&&echo 6:清理Nuget
echo,&&echo 7:发布Nuget包
echo,&&echo 0:退出
echo;
set buildType=0
set /p buildType= 输入任务编号[0] :
echo %buildType%
IF /I "%buildType%"=="1" (echo 1) ELSE (echo not 1)
IF /I "%buildType%"=="1" GOTO RunAll
IF /I "%buildType%"=="2" GOTO BuildRelease
IF /I "%buildType%"=="3" GOTO EncryptionRelease
IF /I "%buildType%"=="4" GOTO NugetRelease
IF /I "%buildType%"=="5" GOTO Clean
IF /I "%buildType%"=="6" GOTO CleanNuget
IF /I "%buildType%"=="7" GOTO Publish
IF /I "%buildType%"=="0" GOTO End
:RunAll
goto Clean
:Clean
@ECHO.
echo 正在清理 %slnName% ......
%ms% %slnName% /t:Clean
echo 清理完成
@ECHO.
IF /I "%buildType%"=="1" (GOTO BuildRelease) ELSE (goto OP)
:BuildRelease
@ECHO.
echo 正在启动Release模式编译 %slnName% ......
%ms% %slnName% /t:Build -p:Configuration="Release" -fileLoggerParameters:FileLogger,Microsoft.Build;logfile=MyLog.Release.log;append -verbosity:Minimal || GOTO ER
echo 编译完成
@ECHO.
IF /I "%buildType%"=="1" (GOTO EncryptionRelease) ELSE (goto OP)
:: 加密方式
:EncryptionRelease
@ECHO.
set rootSource=.\release
set rootSecure=.\_Secure
echo 正在对%slnName% 项目dll进行加密 ......
::echo 删除pdb
::del %rootSource%\*.pdb || echo '删除目录失败:%rootSource%'
echo 清空目录 %rootSecure%
rd /s /q %rootSecure%
REM dotNET_Reactor -file "%rootSource%\YESWEB.Core.dll" -necrobit 1 -control_flow_obfuscation 9 -targetfile ".\_Secure\YESWEB.Core.dll"
REM dotNET_Reactor -file "%rootSource%\YESWEB.EFCore.BulkExtensions.dll" -necrobit 1 -control_flow_obfuscation 9 -targetfile ".\_Secure\YESWEB.EFCore.BulkExtensions.dll"
:: 不能启用necrobit,不然生成的类属性,无法复制,.net core中属性get会直接返回null
for %%I in %_alllist% do (
dotNET_Reactor -file "%rootSource%\%%I.dll" -control_flow_obfuscation 1 -flow_level 9 -targetfile ".\_Secure\%%I.dll"
)
move /y %rootSecure%\*.dll %rootSource%\
echo 加密完成
@ECHO.
IF /I "%buildType%"=="1" (GOTO CleanNuget) ELSE (goto OP)
:CleanNuget
@ECHO.
echo 正在删除缓存...
del /Q .\Nupkgs\*.*
echo 删除缓存完成
@ECHO.
IF /I "%buildType%"=="1" (GOTO NugetRelease) ELSE (goto OP)
:NugetRelease
@ECHO.
echo 正在进行打包...
for %%I in %_alllist% do (
dotnet pack --no-build .\%%I\%%I.csproj -c Release --output .\Nupkgs
)
REM dotnet pack --no-build .\YESWEB.Core\YESWEB.Core.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.EFCore.BulkExtensions\YESWEB.EFCore.BulkExtensions.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.DB.System\YESWEB.DB.System.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.ServerCore\YESWEB.ServerCore.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.DB.Business\YESWEB.DB.Business.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.ServerAuthorize\YESWEB.ServerAuthorize.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.DB.DocNos\YESWEB.DB.DocNos.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.ServerLibs\YESWEB.ServerLibs.csproj -c Release --output .\Nupkgs
REM dotnet pack --no-build .\YESWEB.DocNoProvider\YESWEB.DocNoProvider.csproj -c Release --output .\Nupkgs
echo 打包完成
@ECHO.
goto OP
:Publish
@ECHO.
set nuget="E:\OneDrive\Nuget\NuGet\nuget.exe"
set nuget_Key="---------"
set nuget_url="https://www.nuget.org"
echo 正在进行发布...
dotnet nuget push .\Nupkgs\*.nupkg -k %nuget_Key% -s %nuget_url%
echo 发布完成
@ECHO.
GOTO End
:End
@ECHO.
PAUSE
@ECHO ON
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post 张国生