文章出處
文章列表
使用Visual Studio打開解決方案,對<網站項目>右鍵點擊<發布>,一切都是正常的,所有宏都可用,宏參數值也是正確的。
而通過批處理腳本命令調用MSBuild.exe對解決方案編譯,一切也都是正常的,所有宏都可用,宏參數值也是正確的。
但如果你通過批處理腳本命令調用MSBuild.exe對解決方案下某個Web項目進行發布操作時,你會發現,某些針對解決方案可用的宏變得不正常,不可用,宏參數值都是錯誤的。
例如$(SolutionDir)在某些版本的MSBuild下它的值是"",某些版本的MSBuild下它的值是"..\"。
那么,這個有解決方法嗎?答案是有的。
MSBuild有個/p命令選項,支持外部傳值重置宏參數值。
在批處理命令里添加“/p:SolutionDir=path”選項,即可讓$(SolutionDir)重新變為正常可用。
下面是我某個項目中提供給CI調用的發布/部署腳本文件代碼:
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..\src\ set SolutionName=Demo set SolutionFile=%SolutionPath%%SolutionName%.sln set ProjectName=WebTestset ProjectFile=%SolutionPath%%ProjectName%\1621.%ProjectName%.csproj set PublishProfile=WebTestDeployToRelease set IfUseNuGetReStore=Y % value is Y or N % set IfUpdateNuGetTool=Y % value is Y or N % :Set system level's parameters set Configuration=Release set LogLevel=normal :: Note: That the MSBuild tool version and VisualStudio version and the TargetFramework version have dependencies set VisualStudioVersion=14.0 set TargetFrameworkVersion=4.6.1 set MicrosoftSdkVersion=v10.0A set NuGetPath=%SolutionPath%.nuget\ set NuGetExe=%NuGetPath%NuGet.exe set NuGetArgs=restore "%SolutionFile%" set AspnetMergePath="C:\Program Files (x86)\Microsoft SDKs\Windows\%MicrosoftSdkVersion%\bin\NETFX %TargetFrameworkVersion% Tools" set MSBuildPath=C:\Program Files (x86)\MSBuild\%VisualStudioVersion%\Bin set MSBuildExe=%MSBuildPath%\MSBuild.exe set MSBuildArgs=/p:Configuration=%Configuration%;VisualStudioVersion=%VisualStudioVersion%;TargetFrameworkVersion=%TargetFrameworkVersion%;SolutionDir=%SolutionPath% /p:DeployOnBuild=true;PublishProfile=%PublishProfile% /p:AspnetMergePath=%AspnetMergePath% /verbosity:%LogLevel% /l:FileLogger,Microsoft.Build.Engine;encoding=utf-8;append=true;logfile=build\%ProjectName%_%Configuration%_Publish.log echo Publish parameters initialize completed. 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 publishing... "%MSBuildExe%" %MSBuildArgs% "%ProjectFile%" echo Publish completed.
感謝偉大的stackoverflow論壇,給我提供了很多幫助。
答案來自于:
文章列表
全站熱搜