Fork me on GitHub

[bash-shell]构建WebAPI项目并且发布到本地

:: 清理log文件
del /S *.log

echo Publish parameters initializing...

::These parameters are not used for the time being
::set DotNetFrameworkPath=%windir%\Microsoft.NET\Framework
::if exist %windir%\SysWOW64 set DotNetFrameworkPath=%windir%\Microsoft.NET\Framework64

:Set user level's parameters
set SolutionPath=%~dp0..\
set SolutionName=ERP
set SolutionFile="%SolutionPath%%SolutionName%.sln"
set ProjectNames=API1 API2 API3
set PackageNames=API1 API2 API3 Job
set BuildPath=%~dp0..\Builds\
set ZipExe="C:\Program Files\7-Zip\7z.exe"
set IfUseNuGetReStore=N % value is Y or N %
set IfUpdateNuGetTool=N % value is Y or N %

:Set system level's parameters
set Configuration=Debug
set LogLevel=normal
:: Note: That the MSBuild tool version and VisualStudio version and the TargetFramework version have dependencies
set MsBuildToolsVersion=14.0
set TargetFrameworkVersion=4.5

set MSBuildPath=C:\Program Files (x86)\MSBuild\%MsBuildToolsVersion%\Bin
set MSBuildExe="%MSBuildPath%\MSBuild.exe"

set MSBuildBuildArgs=/t:Rebuild /toolsversion:%MsBuildToolsVersion% /verbosity:%LogLevel% /logger:FileLogger,Microsoft.Build.Engine;encoding=utf-8;append=true;logfile="%BuildPath%%SolutionName%_Build_%Configuration%.log" /p:Configuration=%Configuration%

set NuGetPath=%SolutionPath%.nuget\
set NuGetExe="%NuGetPath%NuGet.exe"
set NuGetArgs=restore %SolutionFile%

echo Publish parameters initialize completed.

:: 更新NuGet包
if %IfUseNuGetReStore% == Y (
	if %IfUpdateNuGetTool% == Y (
		echo NuGet tools Start updating...
		%NuGetExe% update -Self
		echo NuGet tools update completed.
	) else (
		echo Not update NuGet tools.
	)
	echo NuGet Start ReStoreing...
	%NuGetExe% %NuGetArgs%
	echo NuGet ReStore completed.
) else (
	echo Not use NuGet tools.
)

:: 构建解决方案
echo Start solution building...
%MSBuildExe% %SolutionFile% %MSBuildBuildArgs%
echo Build solution completed.

:: Win项目发布
echo Start JobConsole project publishing...
%MSBuildExe% "%SolutionPath%JobConsole\JobConsole.csproj" /t:Rebuild /verbosity:%LogLevel% /logger:FileLogger,Microsoft.Build.Engine;encoding=utf-8;append=true;logfile="%BuildPath%JobConsole_Publish_%Configuration%.log" /p:Configuration=%Configuration% /p:Platform=AnyCPU /p:OutputPath="%BuildPath%JobConsole"
echo Publish JobConsole project completed.

:: Web项目发布
(for %%p in (%ProjectNames%) do (
	echo Start %%p project publishing...
	%MSBuildExe% "%SolutionPath%%%p\%%p.csproj" /t:WebPublish /verbosity:%LogLevel% /logger:FileLogger,Microsoft.Build.Engine;encoding=utf-8;append=true;logfile="%BuildPath%%%p_Publish_%Configuration%.log" /p:Configuration=%Configuration% /p:Platform=AnyCPU /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl="%BuildPath%%%p"
))

:: 7-zip打包
(for %%p in (%PackageNames%) do (
	echo Start %%p project packing...
	%ZipExe% a -t7z "%BuildPath%%%p_%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.7z" "%BuildPath%%%p/*" -r -x!*.config -x!*bak
	echo Pack %%p project completed.
))

posted @ 2019-09-07 16:53  VAllen  阅读(381)  评论(0编辑  收藏  举报