dotnet cli 发布脚本
publish_remote.bat
- 该脚本实现一键主要发布到远程的共享文件夹中
@echo off
:: 定义变量 SHARE_PATH:共享文件夹, SOURCE_DIR:代码发布的文件夹, TARGET_DIR:目标文件夹(共享文件夹的映射)
set PRO_PATH=.\WebApp
set SHARE_PATH=\\pcmesone\Report
set SOURCE_DIR=%PRO_PATH%\bin\Release\V1
set TARGET_DIR=Z:\V98
:: 清空 SOURCE_DIR 文件夹
if exist "%SOURCE_DIR%" (
rmdir /s /q "%SOURCE_DIR%"
mkdir "%SOURCE_DIR%"
)
dotnet publish %PRO_PATH% -c Release --runtime win-x64 --self-contained false -o %SOURCE_DIR%
:: 映射网络驱动器
net use %TARGET_DIR:~0,2% %SHARE_PATH% /persistent:no
:: 检查是否成功映射
if %errorlevel% neq 0 (
echo Failed to connect to the network share.
exit /b
)
:: 检查目标文件夹是否存在文件
if exist "%TARGET_DIR%\*" (
echo The target directory %TARGET_DIR% already contains files.
echo Please check and delete the existing files if necessary.
net use %TARGET_DIR:~0,2% /delete
exit /b
)
:: 创建目标文件夹
mkdir "%TARGET_DIR%"
:: 检查是否成功创建文件夹
if %errorlevel% neq 0 (
echo Failed to create the target directory.
net use %TARGET_DIR:~0,2% /delete
exit /b
)
:: 使用 xcopy 复制文件和文件夹
xcopy "%SOURCE_DIR%" "%TARGET_DIR%" /E /I
:: 检查是否成功复制
if %errorlevel% neq 0 (
echo Failed to copy the files and folders.
) else (
echo Files and folders have been copied successfully.
)
:: 断开网络驱动器连接
net use %TARGET_DIR:~0,2% /delete
echo "----------------Publish And Send Success----------------"
publib_local.bat
@echo off
:: 定义变量
set PRO_PATH=.\WebApp
set TARGET_DIR=Z:\V98
set SOURCE_DIR=%PRO_PATH%\bin\Release\V1
:: 清空 SOURCE_DIR 文件夹
if exist "%SOURCE_DIR%" (
rmdir /s /q "%SOURCE_DIR%"
mkdir "%SOURCE_DIR%"
)
dotnet publish %PRO_PATH% -c Release --runtime win-x64 --self-contained false -o %SOURCE_DIR%
:: 检查是否成功映射
if %errorlevel% neq 0 (
echo Failed to connect to the network share.
exit /b
)
:: 检查目标文件夹是否存在文件
if exist "%TARGET_DIR%\*" (
echo The target directory %TARGET_DIR% already contains files.
echo Please check and delete the existing files if necessary.
net use %TARGET_DIR:~0,2% /delete
exit /b
)
:: 创建目标文件夹
mkdir "%TARGET_DIR%"
:: 检查是否成功创建文件夹
if %errorlevel% neq 0 (
echo Failed to create the target directory.
net use %TARGET_DIR:~0,2% /delete
exit /b
)
:: 使用 xcopy 复制文件和文件夹
xcopy "%SOURCE_DIR%" "%TARGET_DIR%" /E /I
:: 检查是否成功复制
if %errorlevel% neq 0 (
echo Failed to copy the files and folders.
) else (
echo Files and folders have been copied successfully.
)
echo "----------------Publish And Send Success----------------"
标签:bat,shell,cli,echo,SOURCE,文件夹,DIR%,DIR,TARGET
From: https://www.cnblogs.com/zhuoss/p/18533119