[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.
))

作者:VAllen
出处:http://www.cnblogs.com/vallen
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
唯有偏执者得以生存。
posted @ 2019-09-07 16:53  VAllen  阅读(314)  评论(0编辑  收藏  举报