1 <?xml version="1.0" encoding="utf-8"?>
2 <Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4 <UsingTask TaskName="ExecWithRetriesForNuGetPush" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
7 Utility target for pushing a set of packages using the ExecWithRetriesForNuGetPush task.
8 The per-package retries make this target more reliable than using NuGet.exe
11 <Target Name="NuGetPush">
12 <!-- Interpret an input glob for easy direct usage from command line. -->
13 <ItemGroup Condition="'$(PackagesGlob)'!=''">
14 <PackagesToPush Include="$(PackagesGlob)" />
17 <Error Text="NuGetSource property is not defined."
18 Condition="'$(NuGetSource)'==''" />
21 <NuGetTimeout Condition="'$(NuGetTimeout)'==''">600</NuGetTimeout>
22 <NuGetVerbosity Condition="'$(NuGetVerbosity)'==''">Detailed</NuGetVerbosity>
24 <NuGetPushArgsBase>$(NuGetPushArgsBase) push</NuGetPushArgsBase>
25 <NuGetPushArgsBase>$(NuGetPushArgsBase) -Source $(NuGetSource)</NuGetPushArgsBase>
26 <NuGetPushArgsBase>$(NuGetPushArgsBase) -Timeout $(NuGetTimeout)</NuGetPushArgsBase>
27 <NuGetPushArgsBase>$(NuGetPushArgsBase) -Verbosity $(NuGetVerbosity)</NuGetPushArgsBase>
28 <NuGetPushArgsBase Condition="'$(NuGetApiKey)'!=''">$(NuGetPushArgsBase) -ApiKey $(NuGetApiKey)</NuGetPushArgsBase>
30 <IgnorableErrorMessagesExistingPackageMessage>Overwriting existing packages is forbidden according to the package retention settings for this feed.</IgnorableErrorMessagesExistingPackageMessage>
34 <NuGetPushCommand Include="@(PackagesToPush -> '$(NuGetExePath) $(NuGetPushArgsBase) %(Identity)')">
35 <PackageToPush>%(Identity)</PackageToPush>
38 <!-- There are special failure scenarios that we want to ignore. Those scenarios are
39 when NuGet reports a failure during a push attempt for something server or timeout related,
40 and then gets a "Forbidden" response on the next attempt because the package "already exists".
41 This indicates that the failure was reported, but the push was actually successful.
43 <IgnorableErrorMessages Include="$(IgnorableErrorMessagesExistingPackageMessage)">
44 <ConditionalErrorMessage>Pushing took too long</ConditionalErrorMessage>
45 </IgnorableErrorMessages>
46 <IgnorableErrorMessages Include="$(IgnorableErrorMessagesExistingPackageMessage)">
47 <ConditionalErrorMessage>The connection with the server was terminated abnormally</ConditionalErrorMessage>
48 </IgnorableErrorMessages>
49 <IgnorableErrorMessages Include="$(IgnorableErrorMessagesExistingPackageMessage)">
50 <ConditionalErrorMessage>An existing connection was forcibly closed by the remote host</ConditionalErrorMessage>
51 </IgnorableErrorMessages>
54 <ExecWithRetriesForNuGetPush
55 Command="%(NuGetPushCommand.Identity)"
56 MaxAttempts="$(MaxAttempts)"
57 RetryDelayBase="$(RetryDelayBase)"
58 RetryDelayConstant="$(RetryDelayConstant)"
59 IgnoredErrorMessagesWithConditional="@(IgnorableErrorMessages)"
60 PackageFile="%(NuGetPushCommand.PackageToPush)"
61 PassIfIdenticalV2Feed="$(PassIfIdenticalV2Feed)" />