Repository navigation
Expand file tree
/
Copy pathNuGet.Restore.targets
More file actions
69 lines (60 loc) · 3.39 KB
/
Copy pathNuGet.Restore.targets
File metadata and controls
69 lines (60 loc) · 3.39 KB
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
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<NuGetPath>$(MSBuildThisFileDirectory).nuget</NuGetPath>
<NuGetExe>$(NuGetPath)\NuGet.exe</NuGetExe>
<CachedNuGet>$(LocalAppData)\NuGet\NuGet.exe</CachedNuGet>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<NuGetExe>nuget</NuGetExe>
</PropertyGroup>
<Target Name="RestorePackages" BeforeTargets="Build" DependsOnTargets="GetNuGet">
<!-- Restores current solution being build first -->
<Exec Command='"$(NuGetExe)" Restore "$(SolutionPath)"' Condition="'$(SolutionPath)' != ''" />
<!-- Restores additional solutions -->
<Exec Command='"$(NuGetExe)" Restore "%(RestoreSolution.Identity)"' Condition="'%(RestoreSolution.Identity)' != '' And '%(RestoreSolution.OutputDirectory)' == ''" />
<Exec Command='"$(NuGetExe)" Restore "%(RestoreSolution.Identity)" -OutputDirectory "%(RestoreSolution.OutputDirectory)"' Condition="'%(RestoreSolution.Identity)' != '' And '%(RestoreSolution.OutputDirectory)' != ''" />
</Target>
<Target Name="GetNuGet" Condition="'$(OS)' == 'Windows_NT' And !Exists('$(NuGetExe)')">
<MakeDir Directories="$(NuGetPath)" Condition="!Exists($(NuGetPath))" />
<DownloadNuGet TargetPath="$(CachedNuGet)" Condition="!Exists($(NuGetExe)) And !Exists($(CachedNuGet))" />
<Copy SourceFiles="$(CachedNuGet)" DestinationFolder="$(NuGetPath)" Condition="!Exists($(NuGetExe))" />
</Target>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<CodeTaskAssembly Condition="'$(MSBuildAssemblyVersion)' == ''">$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll</CodeTaskAssembly>
<!-- In VS2013, the assembly contains the VS version. -->
<CodeTaskAssembly Condition="'$(MSBuildAssemblyVersion)' == '12.0'">$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll</CodeTaskAssembly>
<!-- In VS2015+, the assembly was renamed, hopefully this will be the last condition! -->
<CodeTaskAssembly Condition="'$(MSBuildAssemblyVersion)' != '' and '$(MSBuildAssemblyVersion)' >= '14.0'">$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll</CodeTaskAssembly>
</PropertyGroup>
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(CodeTaskAssembly)">
<ParameterGroup>
<TargetPath ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
TargetPath = Path.GetFullPath(TargetPath);
if (!Directory.Exists(Path.GetDirectoryName(TargetPath)))
Directory.CreateDirectory(Path.GetDirectoryName(TargetPath));
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", TargetPath);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>