1 <?xml version="1.0" encoding="utf-8"?>
2 <Project ToolsVersion="12.0" InitialTargets="_RestoreBuildToolsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
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">
7 <Address ParameterType="System.String" Required="true" />
8 <FileName ParameterType="System.String" Required="true" />
11 <Reference Include="System" />
12 <Reference Include="System.IO" />
13 <Code Type="Fragment" Language="cs">
15 var directory = System.IO.Path.GetDirectoryName(FileName);
16 Directory.CreateDirectory(directory);
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;
25 while (tryCount <= maxTries)
29 Log.LogMessage("Attempting to download {0}...", Address);
30 client.DownloadFile(Address, tempFile);
33 catch (System.Net.WebException e)
36 if (tryCount > maxTries)
42 Log.LogMessage(MessageImportance.High, "Download failed, retrying: {0}", e.Message);
49 if (!File.Exists(FileName))
50 File.Move(tempFile, FileName);
54 if (File.Exists(tempFile))
55 File.Delete(tempFile);
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.
66 <Target Name="_RestoreBuildToolsWrapper" DependsOnTargets="_RestoreBuildTools" />
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..." />
73 <Copy Condition="Exists('$(NuGetCachedPath)')" SourceFiles="$(NuGetCachedPath)" DestinationFiles="$(NuGetToolPath)" SkipUnchangedFiles="true" />
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'" />
80 <Exec Command="curl -sSL --create-dirs -o $(NuGetToolPath) https://api.nuget.org/downloads/nuget.exe"
81 Condition="!Exists('$(NuGetToolPath)') and '$(OsEnvironment)'=='Unix'" />
84 <_RestoreBuildToolsCommand>$(NugetRestoreCommand) "$(SourceDir).nuget/packages.$(OsEnvironment).config"</_RestoreBuildToolsCommand>
87 <!-- Restore build tools -->
88 <Exec Command="$(_RestoreBuildToolsCommand)" StandardOutputImportance="Low" />
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" /> -->
99 <!-- Add DNU and Roslyn tool execute rights -->
100 <Exec Condition="'$(OsEnvironment)'=='Unix'"
101 Command="chmod a+x "$(DnxPackageDir)/bin/dnu"" />
102 <Exec Condition="'$(OsEnvironment)'=='Unix'"
103 Command="chmod a+x "$(DnxPackageDir)/bin/dnx"" />
104 <Exec Condition="'$(OsEnvironment)'=='Unix'"
105 Command="find '$(RoslynPackageDir)tools' -name "*.exe" -exec chmod "+x" '{}' ';'" />
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." />
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).
116 <Touch Files="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)" />
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" />
122 <Target Name="Test" />