且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在TFS构建中获取nuget恢复

更新时间:2023-02-02 17:19:25

根据此博文 Build.proj 文件的一部分。

您需要添加 Build.proj 并将其作为内容:

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>

或者,您可以从自定义预构建脚本

或者,自定义XAML模板并添加一个Foreach循环来调用:

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.