Fork me on GitHub

在CI (Jenkins) 从机(服务器)上使用bat批处理执行自动构建任务时,输出NuGet还原失败的解决方案

编译环境:Jenkins+MSBuilds

 

1.搜索本次构建的解决方案中的所有csproj后缀文件,打开后找到这一段代码,并且删除掉。如果没有,直接忽略跳过。

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  ...
</Target>

这里因为在Visual Studio 2015中(对应的MSbuild版本是V14.0),已不再需要这一段代码配置。

 

2.增加命令:nuget.exe update -Self

echo Start initialize build parameters

::set DotNetFrameworkPath=%windir%\Microsoft.NET\Framework
::if exist %windir%\SysWOW64 set DotNetFrameworkPath=%windir%\Microsoft.NET\Framework64


set SolutionName=Uniqlo
set Configuration=Debug
set LogLevel=normal

set SolutionPath=%~dp0..\src\
set SolutionFile=%SolutionPath%%SolutionName%.sln

set NugetExe=%SolutionPath%.nuget\NuGet.exe
set NugetArgs=restore "%SolutionFile%"

set MSBuildPath=C:\Program Files (x86)\MSBuild\14.0\Bin
set MSBuildExe=%MSBuildPath%\MSBuild.exe
set MSBuildArgs=/t:Rebuild /p:Configuration=%Configuration%;VisualStudioVersion=14.0;TargetFrameworkVersion=4.6.1 /verbosity:%LogLevel% /l:FileLogger,Microsoft.Build.Engine;encoding=utf-8;append=true;logfile=build\%SolutionName%_%Configuration%_Build.log

echo Initialize build parameters completed.

echo NuGet Start ReStoreing...
"%NugetExe%" update -Self
"%NugetExe%" %NugetArgs%
echo NuGet ReStore completed.

echo MSBuild Start building...
"%MSBuildExe%" %MSBuildArgs% "%SolutionFile%"
echo MSBuild Build completed.

 

本解决方案同样适用于在本地机器中使用VS2015编译出现NuGet还原包失败的情况。

如有此情况,在搜索并使用其它方案未果,排除其它原因(例如网络问题,被墙等),可以使用本解决方案试试。

 

posted @ 2017-07-14 17:50  VAllen  阅读(1188)  评论(0编辑  收藏  举报