How to get nuget restore in TFS build

北城以北 提交于 2019-12-02 02:06:05

问题


I can't make it work TFS build. It is nuget restore issue. Nuget is not restoring reference dll files.

Here is belwo my build configuration. Please advise me how I can make this works.


回答1:


As per this blog post on Nuget's website you can use the command line you mentioned, but it has to be part of a custom target using a Build.proj file.

You need to add a Build.proj and put this as the contents:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
         DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)bin\</OutDir>
    <Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
    <SourceHome Condition=" '$(SourceHome)'=='' ">$(MSBuildThisFileDirectory)src\</SourceHome>
    <ToolsHome Condition=" '$(ToolsHome)'=='' ">$(MSBuildThisFileDirectory)tools\</ToolsHome>
  </PropertyGroup>

  <ItemGroup>
    <Solution Include="$(SourceHome)*.sln">
      <AdditionalProperties>OutDir=$(OutDir);Configuration=$(Configuration)</AdditionalProperties>
    </Solution>
  </ItemGroup>

  <Target Name="RestorePackages">
    <Exec Command="&quot;$(ToolsHome)NuGet\NuGet.exe&quot; restore &quot;%(Solution.Identity)&quot;" />
  </Target>

  <Target Name="Clean">
    <MSBuild Targets="Clean"
             Projects="@(Solution)" />
  </Target>

  <Target Name="Build" DependsOnTargets="RestorePackages">
    <MSBuild Targets="Build"
             Projects="@(Solution)" />
  </Target>

  <Target Name="Rebuild" DependsOnTargets="RestorePackages">
    <MSBuild Targets="Rebuild"
             Projects="@(Solution)" />
  </Target>

</Project>

Alternatively, you could call it from a custom Pre-Build Script.

Or, customise the XAML template and add a Foreach loop to invoke:

nuget.exe restore path\to\solution.sln

on each solution in the build definition.




回答2:


Here are some steps (described here which was mentioned in Dave's post) you need to follow in order to have these NuGet packages restored during the VSO (TFS) build process.

  1. Add following items to the solution. (Content of the nuget.config and .tfignore file can be found here)

  1. Add one build.proj file under the root path of the solution folder. (Content of the build.proj file can be found here)

  2. Create one folder named tools under the root path of the solution folder. Create NuGet sub-folder under tools folder, download and save nuget.exe under tools\NuGet path.

  3. Check in nuget.config, .tfignore, build.proj and tools\NuGet\nuget.exe into TFS version control.

  4. Modify the build definition to choose to build the build.proj file.

Then you will have NuGet packages restored successfully during the TFS build process.



来源:https://stackoverflow.com/questions/33565296/how-to-get-nuget-restore-in-tfs-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!