This repository has been archived by the owner on Sep 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NuGet.Restore.targets
86 lines (70 loc) · 4.04 KB
/
NuGet.Restore.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<NuGetPath Condition=" '$(NuGetPath)' == '' ">$(MSBuildThisFileDirectory).nuget</NuGetPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<NuGet Condition=" '$(NuGet)' == '' ">$(NuGetPath)\NuGet.exe</NuGet>
<CachedNuGet Condition=" '$(CachedNuGet)' == '' ">$(LocalAppData)\NuGet\NuGet.exe</CachedNuGet>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
<NuGet>nuget</NuGet>
</PropertyGroup>
<!-- Add current solution as one more solution to restore -->
<ItemGroup>
<RestoreSolution Include="$(SolutionPath)" Condition="'$(SolutionPath)' != ''" />
</ItemGroup>
<ItemDefinitionGroup>
<RestoreSolution>
<Command>Restore</Command>
<Args></Args>
</RestoreSolution>
</ItemDefinitionGroup>
<Target Name="RestorePackages" BeforeTargets="Build"
DependsOnTargets="_GetNuGet;EnsureBeforeSolutionImport;RestoreSolutions"
Condition=" '$(RestorePackages)' != 'false' " />
<Target Name="EnsureBeforeSolutionImport">
<Error Text="This targets file should ONLY be imported from a file named Before.$(SolutionFileName).targets alongside the solution file."
Condition="!$(MSBuildProjectFile.Contains('$(SolutionFileName)'))" />
</Target>
<Target Name="RestoreSolutions" Inputs="@(RestoreSolution)" Outputs="%(RestoreSolution.Identity)-BATCH">
<PropertyGroup>
<!-- Normalizes paths to all be relative to the RestoreDir, to shorten the Exec Command length -->
<_NuGet>$(NuGet.Replace('$(RestoreDir)', '').TrimStart('/').TrimStart('\'))</_NuGet>
</PropertyGroup>
<CreateProperty Value="%(RestoreSolution.Command)">
<Output PropertyName="_RestoreCommand" TaskParameter="Value" />
</CreateProperty>
<CreateProperty Value="%(RestoreSolution.FullPath)">
<Output PropertyName="_RestoreSolution" TaskParameter="Value" />
</CreateProperty>
<CreateProperty Value="%(RestoreSolution.OutputDirectory)">
<Output PropertyName="_RestoreOutput" TaskParameter="Value" />
</CreateProperty>
<CreateProperty Value="%(RestoreSolution.Args)">
<Output PropertyName="_RestoreArgs" TaskParameter="Value" />
</CreateProperty>
<PropertyGroup>
<_RestoreSolution Condition=" '$(OS)' != 'Unix' ">$(_RestoreSolution.Replace('$(RestoreDir)', '').TrimStart('/').TrimStart('\'))</_RestoreSolution>
<_RestoreOutput Condition=" '$(OS)' != 'Unix' And '$(_RestoreOutput)' != ''">$(_RestoreOutput.Replace('$(RestoreDir)', '').TrimStart('/').TrimStart('\'))</_RestoreOutput>
<!-- The default value from ItemDefinitionGroup isn't being honored by xbuild, sigh :( -->
<_RestoreCommand Condition=" '$(_RestoreCommand)' == '' ">Restore</_RestoreCommand>
</PropertyGroup>
<Exec Command='"$(_NuGet)" $(_RestoreCommand) "$(_RestoreSolution)" $(_RestoreArgs)'
Condition="'$(_RestoreOutput)' == ''"
WorkingDirectory="$(RestoreDir)" />
<Exec Command='"$(_NuGet)" $(_RestoreCommand) "$(_RestoreSolution)" -OutputDirectory "$(_RestoreOutput)" $(_RestoreArgs)'
Condition="'$(_RestoreOutput)' != ''"
WorkingDirectory="$(RestoreDir)" />
</Target>
<Target Name="_GetNuGet" Condition=" '$(OS)' == 'Windows_NT' And !Exists('$(NuGet)') ">
<PropertyGroup>
<PowerShell Condition=" '$(PowerShell)' == '' ">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShell>
</PropertyGroup>
<MakeDir Directories="$(NuGetPath)" Condition=" !Exists($(NuGetPath)) " />
<MakeDir Directories="$(LocalAppData)\NuGet" Condition=" !Exists('$(LocalAppData)\NuGet') " />
<Exec Command=""$(PowerShell)" -Command "& { (New-Object System.Net.WebClient).DownloadFile('http://nuget.org/nuget.exe', '$(CachedNuGet)') }""
Condition=" !Exists($(NuGet)) And !Exists($(CachedNuGet)) " />
<Copy SourceFiles="$(CachedNuGet)" DestinationFolder="$(NuGetPath)" Condition="!Exists($(NuGet))" />
</Target>
</Project>