forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir.targets
115 lines (100 loc) · 5.19 KB
/
dir.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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" InitialTargets="_RestoreBuildToolsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Inline task to bootstrap the build to enable downloading nuget.exe -->
<UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<Address ParameterType="System.String" Required="true" />
<FileName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System" />
<Reference Include="System.IO" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var directory = System.IO.Path.GetDirectoryName(FileName);
Directory.CreateDirectory(directory);
var tempFile = Path.Combine(directory, Path.GetRandomFileName());
var client = new System.Net.WebClient();
var tryCount = 1;
var maxTries = 3;
while (tryCount <= maxTries)
{
try
{
Log.LogMessage("Attempting to download {0}...", Address);
client.DownloadFile(Address, tempFile);
break;
}
catch (System.Net.WebException e)
{
tryCount++;
if (tryCount > maxTries)
{
throw;
}
else
{
Log.LogMessage(MessageImportance.High, "Download failed, retrying: {0}", e.Message);
}
}
}
try
{
if (!File.Exists(FileName))
File.Move(tempFile, FileName);
}
finally
{
if (File.Exists(tempFile))
File.Delete(tempFile);
}
]]>
</Code>
</Task>
</UsingTask>
<!--
Needed to avoid the IntialTargets from having an Output which ends up getting
added to the output references when you have a project to project reference.
-->
<Target Name="_RestoreBuildToolsWrapper" DependsOnTargets="_RestoreBuildTools" />
<Target Name="_RestoreBuildTools"
Inputs="$(MSBuildThisFileDirectory)dir.props;$(SourceDir).nuget\packages.config"
Outputs="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)">
<Message Importance="High" Text="Restoring build tools..." />
<!-- Download latest nuget.exe -->
<DownloadFile FileName="$(NuGetToolPath)"
Address="https://www.nuget.org/nuget.exe"
Condition="!Exists('$(NuGetToolPath)')" />
<PropertyGroup>
<_RestoreBuildToolsCommand>$(NugetRestoreCommand) "$(SourceDir).nuget/packages.config"</_RestoreBuildToolsCommand>
</PropertyGroup>
<!-- Restore build tools -->
<Exec Command="$(_RestoreBuildToolsCommand)" StandardOutputImportance="Low" />
<!-- currently DNU doesn't support -ConfigFile: https://github.com/aspnet/dnx/issues/1693
Our DnuRestoreCommand doesn't force a config file and we rely on the
directory probing for it to find nuget.config. This works for restore from source,
but not restore from PackagesDir as happens for test project restore since PackagesDir
will not be under src. To workaround, copy our nuget.config to packages. -->
<Copy Condition="Exists('$(NuGetConfigFile)')" SourceFiles="$(NuGetConfigFile)" DestinationFolder="$(PackagesDir)" SkipUnchangedFiles="true" />
<Copy Condition="Exists('$(NuGetConfigFile)')" SourceFiles="$(NuGetConfigFile)" DestinationFolder="$(IntermediateOutputRootPath)" SkipUnchangedFiles="true" />
<!-- Add DNU and Roslyn tool execute rights -->
<Exec Condition="'$(OsEnvironment)'=='Unix'"
Command="chmod a+x "$(DnxPackageDir)/bin/dnu"" />
<Exec Condition="'$(OsEnvironment)'=='Unix'"
Command="chmod a+x "$(DnxPackageDir)/bin/dnx"" />
<Exec Condition="'$(OsEnvironment)'=='Unix'"
Command="find '$(RoslynPackageDir)tools' -name "*.exe" -exec chmod "+x" '{}' ';'" />
<Error Condition="'$(ErrorIfBuildToolsRestoredFromIndividualProject)'=='true'"
Text="The build tools package was just restored and so we cannot continue the build of an individual project because targets from the build tools package were not able to be imported. Please retry the build the individual project again." />
<!--
There are cases where the inputs could be newer than the outputs but the
download or restore may not need to update. In such cases we need to touch
these files otherwise we continually run this target over and over for
every project until these files are cleaned (if the are ever cleaned).
-->
<Touch Files="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)" />
</Target>
<!-- Provide default empty targets for BuildAndTest and Test which can be hooked onto or overridden as necessary -->
<Target Name="BuildAndTest" DependsOnTargets="Build;Test" />
<Target Name="Test" />
</Project>