forked from nblockchain/geewallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NuGet.Restore.targets
170 lines (142 loc) · 8.36 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NuGetPath Condition=" '$(NuGetPath)' == '' ">$(MSBuildThisFileDirectory).nuget</NuGetPath>
<NuGetUrl Condition=" '$(NuGetUrl)' == '' ">https://dist.nuget.org/win-x86-commandline/v5.4.0/nuget.exe</NuGetUrl>
<NuGet Condition=" '$(NuGet)' == '' ">$(NuGetPath)\nuget.exe</NuGet>
<Mono Condition=" '$(OS)' != 'Windows_NT' ">mono</Mono>
<TEMP Condition=" '$(OS)' != 'Windows_NT' ">$(TMPDIR)</TEMP>
<BaseUrl Condition=" '$(BaseUrl)' == '' ">https://raw.githubusercontent.com/kzu/NuGet.Restore/master/</BaseUrl>
<CurlUrl Condition=" '$(CurlUrl)' == '' ">$(BaseUrl)curl.exe</CurlUrl>
<CurlArgs Condition=" '$(CurlArgs)' == '' ">-k -f -L</CurlArgs>
<Curl Condition=" '$(OS)' == 'Windows_NT' ">"$(TEMP)\curl.exe" $(CurlArgs)</Curl>
<Curl Condition=" '$(OS)' != 'Windows_NT' ">curl $(CurlArgs)</Curl>
<PowerShell Condition=" '$(PowerShell)' == '' ">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShell>
<!-- see https://learn.microsoft.com/en-us/visualstudio/msbuild/task-element-msbuild -->
<ContinueOnRestoreError Condition=" '$(ContinueOnRestoreError)' == '' ">ErrorAndStop</ContinueOnRestoreError>
<RestoreVerbosity Condition="'$(RestoreVerbosity)' == ''">quiet</RestoreVerbosity>
<RestoreLoggingVerbosity Condition="'$(RestoreLoggingVerbosity)' == ''">normal</RestoreLoggingVerbosity>
<TargetsFile>$(MSBuildThisFilename)$(MSBuildThisFileExtension)</TargetsFile>
</PropertyGroup>
<!-- Add current solution as one more solution to restore -->
<ItemGroup>
<RestoreSolution Include="$(SolutionPath)" Condition=" '$(SolutionPath)' != '' " />
</ItemGroup>
<ItemDefinitionGroup>
<RestoreSolution>
<Command>Restore</Command>
<Args>-verbosity $(RestoreLoggingVerbosity)</Args>
</RestoreSolution>
</ItemDefinitionGroup>
<Target Name="RestorePackages" BeforeTargets="Build"
DependsOnTargets="DownloadNuGet;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>
<!-- The base restore directory can be overriden via the Before.*.targets file, but we default to the solution path, like NuGet does -->
<RestoreDir Condition=" '$(RestoreDir)' == '' And '$(SolutionPath)' != '' ">$([System.IO.Path]::GetDirectoryName('$(SolutionPath)'))</RestoreDir>
</PropertyGroup>
<PropertyGroup>
<_NuGet>$(NuGet)</_NuGet>
<_RestoreDir>$(RestoreDir)</_RestoreDir>
<_RestoreDir Condition="'$(_RestoreDir)' == ''">%(RestoreSolution.RootDir)%(RestoreSolution.Directory)</_RestoreDir>
<!-- Normalizes paths to all be relative to the RestoreDir, to shorten the Exec Command length -->
<_NuGet Condition=" '$(RestoreDir)' != ''">$(_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' And '$(_RestoreDir)' != ''">$(_RestoreSolution.Replace('$(_RestoreDir)', '').TrimStart('/').TrimStart('\'))</_RestoreSolution>
<_RestoreOutput Condition=" '$(OS)' != 'Unix' And '$(_RestoreOutput)' != '' And '$(_RestoreDir)' != ''">$(_RestoreOutput.Replace('$(_RestoreDir)', '').TrimStart('/').TrimStart('\'))</_RestoreOutput>
<!-- The default value from ItemDefinitionGroup isn't being picked up by xbuild -->
<_RestoreCommand Condition=" '$(_RestoreCommand)' == '' ">Restore</_RestoreCommand>
</PropertyGroup>
<Message Importance="$(RestoreLoggingImportance)" Text="Restoring $(_RestoreSolution)..." />
<Exec Command='$(Mono) "$(_NuGet)" $(_RestoreCommand) "$(_RestoreSolution)" -DisableParallelProcessing $(_RestoreArgs)'
ContinueOnError="$(ContinueOnRestoreError)"
Condition="'$(_RestoreOutput)' == ''"
WorkingDirectory="$(_RestoreDir)" />
<Exec Command='$(Mono) "$(_NuGet)" $(_RestoreCommand) "$(_RestoreSolution)" -DisableParallelProcessing -OutputDirectory "$(_RestoreOutput)" $(_RestoreArgs)'
ContinueOnError="$(ContinueOnRestoreError)"
Condition="'$(_RestoreOutput)' != ''"
WorkingDirectory="$(_RestoreDir)" />
</Target>
<!-- Initializes a Before.[sln].targets file for every solution found recursively -->
<Target Name="Init" DependsOnTargets="DownloadCurl">
<ItemGroup>
<SolutionFile Include="$(MSBuildStartupDirectory)\**\*.sln" />
<SolutionToInit Include="@(SolutionFile)" Condition=" !Exists('%(RootDir)%(Directory)Before.%(Filename)%(Extension).targets') " />
</ItemGroup>
<Exec Command='$(Curl) -o "$(TEMP)\Before.sln.targets" "$(BaseUrl)Before.sln.targets"'
ConsoleToMSBuild="true" />
<Copy SourceFiles="@(SolutionToInit -> '$(TEMP)\Before.sln.targets')"
DestinationFiles="@(SolutionToInit -> '%(RootDir)%(Directory)Before.%(Filename)%(Extension).targets')" />
</Target>
<Target Name="Update" DependsOnTargets="DownloadCurl">
<Exec Command='$(Curl) -I "$(TEMP)\$(TargetsFile)" "$(BaseUrl)$(TargetsFile)"'
StandardOutputImportance='low'
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" ItemName="HttpResponse"/>
</Exec>
<ItemGroup>
<ETag Include="@(HttpResponse)" Condition="$([System.String]::new('%(Identity)').StartsWith('ETag:')) " />
</ItemGroup>
<PropertyGroup>
<ETag>@(ETag)</ETag>
<ETag>$(ETag.Substring(5).Trim().TrimStart('"').TrimEnd('"'))</ETag>
<XmlNs><Namespace Prefix='msb' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/></XmlNs>
<UpdateFile Condition=" '$(UpdateFile)' == '' ">$(MSBuildThisFileFullPath)</UpdateFile>
</PropertyGroup>
<XmlPeek Namespaces="$(XmlNs)"
XmlInputPath="$(MSBuildThisFileFullPath)"
Query="/msb:Project/msb:PropertyGroup/msb:NuGetRestoreETag/text()">
<Output TaskParameter="Result" PropertyName="CurrentETag" />
</XmlPeek>
<Message Importance="high"
Text="New version found, updating $(TargetsFile)."
Condition=" '$(CurrentETag)' != '$(ETag)' " />
<Message Importance="high"
Text="No updates found for $(TargetsFile)."
Condition=" '$(CurrentETag)' == '$(ETag)' " />
<!-- If the retrieved ETag doesn't match the saved one, we need to update the whole file -->
<Exec Command='$(Curl) -o "$(UpdateFile)" "$(BaseUrl)$(TargetsFile)"'
StandardOutputImportance='low'
Condition=" '$(CurrentETag)' != '$(ETag)' " />
<!-- NOTE: known issue, XmlPoke removes the whitespace,
but then users aren't intended to edit the updated
file but the one on the repo instead, via PRs :) -->
<XmlPoke Namespaces="$(XmlNs)"
XmlInputPath="$(UpdateFile)"
Query="/msb:Project/msb:PropertyGroup/msb:NuGetRestoreETag"
Value="$(ETag)"
Condition=" '$(CurrentETag)' != '$(ETag)' " />
</Target>
<Target Name="DownloadNuGet" Condition="!Exists('$(NuGet)')">
<MakeDir Directories="$(NuGetPath)" Condition=" !Exists('$(NuGetPath)') " />
<Exec Condition="'$(OS)' == 'Windows_NT'"
Command=""$(PowerShell)" -NoProfile -Command "& { (New-Object System.Net.WebClient).DownloadFile('$(NuGetUrl)', '$(NuGet)') }"" />
<Exec Condition="'$(OS)' != 'Windows_NT'"
Command='$(Curl) -o "$(NuGet)" "$(NuGetUrl)"' />
</Target>
<Target Name="DownloadCurl" Condition=" '$(OS)' == 'Windows_NT' And !Exists('$(TEMP)\curl.exe') ">
<Exec Command=""$(PowerShell)" -NoProfile -Command "& { (New-Object System.Net.WebClient).DownloadFile('$(CurlUrl)', '$(TEMP)\curl.exe') }"" />
</Target>
<PropertyGroup>
<NuGetRestoreImported>true</NuGetRestoreImported>
<NuGetRestoreETag>1D1D4F4E2A49280</NuGetRestoreETag>
</PropertyGroup>
</Project>