Merge pull request #1263 from adityamandaleeka/contextAlignment
[platform/upstream/coreclr.git] / dir.targets
1 <?xml version="1.0" encoding="utf-8"?>
2 <Project ToolsVersion="12.0" InitialTargets="_RestoreBuildToolsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
4   <!-- Inline task to bootstrap the build to enable downloading nuget.exe -->
5   <UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
6     <ParameterGroup>
7       <Address ParameterType="System.String" Required="true" />
8       <FileName ParameterType="System.String" Required="true" />
9     </ParameterGroup>
10     <Task>
11       <Reference Include="System" />
12       <Reference Include="System.IO" />
13       <Code Type="Fragment" Language="cs">
14         <![CDATA[
15             var directory = System.IO.Path.GetDirectoryName(FileName);
16             Directory.CreateDirectory(directory);
17
18             var tempFile = Path.Combine(directory, Path.GetRandomFileName());
19             var client = new System.Net.WebClient();
20             client.Proxy = System.Net.WebRequest.DefaultWebProxy;
21             if (client.Proxy != null) client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
22             var tryCount = 1;
23             var maxTries = 3;
24
25             while (tryCount <= maxTries)
26             {
27                 try
28                 {
29                     Log.LogMessage("Attempting to download {0}...", Address);
30                     client.DownloadFile(Address, tempFile);
31                     break;
32                 }
33                 catch (System.Net.WebException e)
34                 {
35                     tryCount++;
36                     if (tryCount > maxTries)
37                     {
38                         throw;
39                     }
40                     else
41                     {
42                         Log.LogMessage(MessageImportance.High, "Download failed, retrying: {0}", e.Message);
43                     }
44                 }
45             }
46
47             try
48             {
49                 if (!File.Exists(FileName))
50                     File.Move(tempFile, FileName);
51             }
52             finally
53             {
54                 if (File.Exists(tempFile))
55                     File.Delete(tempFile);
56             }
57         ]]>
58       </Code>
59     </Task>
60   </UsingTask>
61
62   <!--
63     Needed to avoid the IntialTargets from having an Output which ends up getting
64     added to the output references when you have a project to project reference.
65   -->
66   <Target Name="_RestoreBuildToolsWrapper" DependsOnTargets="_RestoreBuildTools" />
67
68   <Target Name="_RestoreBuildTools"
69           Inputs="$(MSBuildThisFileDirectory)dir.props;$(SourceDir).nuget/packages.$(OsEnvironment).config"
70           Outputs="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)">
71     <Message Importance="High" Text="Restoring build tools..." />
72
73     <Copy Condition="Exists('$(NuGetCachedPath)')" SourceFiles="$(NuGetCachedPath)" DestinationFiles="$(NuGetToolPath)" SkipUnchangedFiles="true" />
74
75     <!-- Download latest nuget.exe -->
76     <DownloadFile FileName="$(NuGetToolPath)"
77                   Address="https://www.nuget.org/nuget.exe"
78                   Condition="!Exists('$(NuGetToolPath)') and '$(OsEnvironment)'=='Windows_NT'" />
79
80     <Exec Command="curl -sSL --create-dirs -o $(NuGetToolPath) https://api.nuget.org/downloads/nuget.exe"
81           Condition="!Exists('$(NuGetToolPath)') and '$(OsEnvironment)'=='Unix'" />
82
83     <PropertyGroup>
84       <_RestoreBuildToolsCommand>$(NugetRestoreCommand) "$(SourceDir).nuget/packages.$(OsEnvironment).config"</_RestoreBuildToolsCommand>
85     </PropertyGroup>
86
87     <!-- Restore build tools -->
88     <Exec Command="$(_RestoreBuildToolsCommand)" StandardOutputImportance="Low" />
89
90     <!-- currently DNU doesn't support -ConfigFile: https://github.com/aspnet/dnx/issues/1693
91          Our DnuRestoreCommand doesn't force a config file  and we rely on the
92          directory probing for it to find nuget.config.  This works for restore from source,
93          but not restore from PackagesDir as happens for test project restore since PackagesDir
94          will not be under src.  To workaround, copy our nuget.config to packages. -->
95     <Copy Condition="Exists('$(NuGetConfigFile)')" SourceFiles="$(NuGetConfigFile)" DestinationFolder="$(PackagesDir)" SkipUnchangedFiles="true" />
96     <!-- Add this back if above comment becomes a problem -->
97     <!-- <Copy Condition="Exists('$(NuGetConfigFile)')" SourceFiles="$(NuGetConfigFile)" DestinationFolder="$(IntermediateOutputRootPath)" SkipUnchangedFiles="true" /> -->
98
99     <!-- Add DNU and Roslyn tool execute rights -->
100     <Exec Condition="'$(OsEnvironment)'=='Unix'"
101           Command="chmod a+x &quot;$(DnxPackageDir)/bin/dnu&quot;" />
102     <Exec Condition="'$(OsEnvironment)'=='Unix'"
103           Command="chmod a+x &quot;$(DnxPackageDir)/bin/dnx&quot;" />
104     <Exec Condition="'$(OsEnvironment)'=='Unix'"
105           Command="find '$(RoslynPackageDir)tools' -name &quot;*.exe&quot; -exec chmod &quot;+x&quot; '{}' ';'" />
106
107     <Error Condition="'$(ErrorIfBuildToolsRestoredFromIndividualProject)'=='true'"
108            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." />
109
110     <!--
111       There are cases where the inputs could be newer than the outputs but the
112       download or restore may not need to update. In such cases we need to touch
113       these files otherwise we continually run this target over and over for
114       every project until these files are cleaned (if the are ever cleaned).
115     -->
116     <Touch Files="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)" />
117   </Target>
118
119   <!-- Provide default empty targets for BuildAndTest and Test which can be hooked onto or overridden as necessary -->
120   <Target Name="BuildAndTest" DependsOnTargets="Build;Test" />
121
122   <Target Name="Test" />
123 </Project>