How to get nuget restore in TFS build

2019-08-13 01:15发布

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.

enter image description here

2条回答
叼着烟拽天下
2楼-- · 2019-08-13 01:42

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.

查看更多
来,给爷笑一个
3楼-- · 2019-08-13 01:52

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)

enter image description 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. enter image description here

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

查看更多
登录 后发表回答