2 ***********************************************************************************************
5 WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6 created a backup copy. Incorrect changes to this file will make it
7 impossible to load or build your projects from the command-line or the IDE.
9 Copyright (c) .NET Foundation. All rights reserved.
10 ***********************************************************************************************
12 This target file contains the NuGet Restore target for walking the project and reference graph
13 and restoring dependencies from the graph.
15 Ways to use this targets file:
16 1. Invoke it directly and provide project file paths using $(RestoreGraphProjectInput).
17 2. With a solution this may be used as a target in the metaproj.
18 3. Import the targets file from a project.
21 1. Top level projects (entry points) are determined.
22 2. Each project and all of its project references are walked recursively.
23 3. The project is evaluated for each $(TargetFramework). Items are created
24 for project properties and dependencies. Each item is marked
25 with the project it came from so that it can be matched up later.
26 4. All restore items generated by the walk are grouped together by
27 project and convert into a project spec.
29 The result file contains:
30 1. A list of projects to restore.
31 2. The complete closure of all projects referenced (Includes project references that are not being restored directly).
32 3. Package and project dependencies for each project.
33 4. DotnetCliTool references
35 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
37 <!-- Mark that this target file has been loaded. -->
38 <IsRestoreTargetsFileLoaded>true</IsRestoreTargetsFileLoaded>
39 <!-- Load NuGet.Build.Tasks.dll, this can be overridden to use a different version with $(RestoreTaskAssemblyFile) -->
40 <RestoreTaskAssemblyFile Condition=" '$(RestoreTaskAssemblyFile)' == '' ">NuGet.Build.Tasks.dll</RestoreTaskAssemblyFile>
41 <!-- Do not hide errors and warnings by default -->
42 <HideWarningsAndErrors Condition=" '$(HideWarningsAndErrors)' == '' ">false</HideWarningsAndErrors>
43 <!-- Recurse by default -->
44 <RestoreRecursive Condition=" '$(RestoreRecursive)' == '' ">true</RestoreRecursive>
45 <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
46 <!-- RuntimeIdentifier compatibility check -->
47 <ValidateRuntimeIdentifierCompatibility Condition=" '$(ValidateRuntimeIdentifierCompatibility)' == '' ">false</ValidateRuntimeIdentifierCompatibility>
48 <!-- Error handling while walking projects -->
49 <RestoreContinueOnError Condition=" '$(RestoreContinueOnError)' == '' ">WarnAndContinue</RestoreContinueOnError>
53 <!-- Generate a restore graph for each entry point project. -->
54 <_GenerateRestoreGraphProjectEntryInputProperties>
55 RestoreUseCustomAfterTargets=$(RestoreUseCustomAfterTargets);
56 NuGetRestoreTargets=$(MSBuildThisFileFullPath);
57 BuildProjectReferences=false;
58 ExcludeRestorePackageImports=true;
59 </_GenerateRestoreGraphProjectEntryInputProperties>
62 This is used by NuGet.exe to inject targets into the project that will be
63 walked next. In normal /t:Restore mode this causes a duplicate import
64 since NuGet.targets it loaded as part of MSBuild, there is should be
66 <_GenerateRestoreGraphProjectEntryInputProperties Condition=" '$(RestoreUseCustomAfterTargets)' == 'true' ">
67 $(_GenerateRestoreGraphProjectEntryInputProperties);
68 CustomAfterMicrosoftCommonCrossTargetingTargets=$(MSBuildThisFileFullPath);
69 CustomAfterMicrosoftCommonTargets=$(MSBuildThisFileFullPath);
70 </_GenerateRestoreGraphProjectEntryInputProperties>
74 <UsingTask TaskName="NuGet.Build.Tasks.RestoreTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
75 <UsingTask TaskName="NuGet.Build.Tasks.WriteRestoreGraphTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
76 <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreProjectJsonPathTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
77 <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreProjectReferencesTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
78 <UsingTask TaskName="NuGet.Build.Tasks.GetRestorePackageReferencesTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
79 <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreDotnetCliToolsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
80 <UsingTask TaskName="NuGet.Build.Tasks.GetProjectTargetFrameworksTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
81 <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreSolutionProjectsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
82 <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreSettingsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
83 <UsingTask TaskName="NuGet.Build.Tasks.WarnForInvalidProjectsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
84 <UsingTask TaskName="NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask" AssemblyFile="$(RestoreTaskAssemblyFile)" />
87 ============================================================
89 Main entry point for restoring packages
90 ============================================================
92 <Target Name="Restore" DependsOnTargets="_GenerateRestoreGraph">
94 <!-- Drop any duplicate items -->
96 Inputs="@(_RestoreGraphEntry)">
98 TaskParameter="Filtered"
99 ItemName="_RestoreGraphEntryFiltered" />
102 <!-- Call restore -->
104 RestoreGraphItems="@(_RestoreGraphEntryFiltered)"
105 RestoreDisableParallel="$(RestoreDisableParallel)"
106 RestoreNoCache="$(RestoreNoCache)"
107 RestoreIgnoreFailedSources="$(RestoreIgnoreFailedSources)"
108 RestoreRecursive="$(RestoreRecursive)"
109 RestoreForce="$(RestoreForce)"
110 HideWarningsAndErrors="$(HideWarningsAndErrors)"/>
114 ============================================================
115 GenerateRestoreGraphFile
116 Writes the output of _GenerateRestoreGraph to disk
117 ============================================================
119 <Target Name="GenerateRestoreGraphFile" DependsOnTargets="_GenerateRestoreGraph">
121 <Error Condition="$(RestoreGraphOutputPath) == ''" Text="Missing RestoreGraphOutputPath property!" />
123 <!-- Drop any duplicate items -->
125 Inputs="@(_RestoreGraphEntry)">
127 TaskParameter="Filtered"
128 ItemName="_RestoreGraphEntryFiltered" />
132 <WriteRestoreGraphTask
133 RestoreGraphItems="@(_RestoreGraphEntryFiltered)"
134 RestoreGraphOutputPath="$(RestoreGraphOutputPath)"
135 RestoreRecursive="$(RestoreRecursive)" />
139 ============================================================
140 CollectPackageReferences
141 Gathers all PackageReference items from the project.
142 This target may be used as an extension point to modify
143 package references before NuGet reads them.
144 ============================================================
146 <Target Name="CollectPackageReferences" Returns="@(PackageReference)" />
149 ============================================================
150 _LoadRestoreGraphEntryPoints
151 Find project entry points and load them into items.
152 ============================================================
154 <Target Name="_LoadRestoreGraphEntryPoints" Returns="@(RestoreGraphProjectInputItems)">
156 <!-- Allow overriding items with RestoreGraphProjectInput -->
157 <ItemGroup Condition=" @(RestoreGraphProjectInputItems) == '' ">
158 <RestoreGraphProjectInputItems Include="$(RestoreGraphProjectInput)" />
161 <!-- Project case -->
162 <ItemGroup Condition=" $(MSBuildProjectFullPath.EndsWith('.metaproj')) != 'true' AND @(RestoreGraphProjectInputItems) == '' ">
163 <RestoreGraphProjectInputItems Include="$(MSBuildProjectFullPath)" />
166 <!-- Solution case -->
167 <GetRestoreSolutionProjectsTask
168 Condition=" $(MSBuildProjectFullPath.EndsWith('.metaproj')) == 'true' AND @(RestoreGraphProjectInputItems) == '' "
169 ProjectReferences="@(ProjectReference)"
170 SolutionFilePath="$(MSBuildProjectFullPath)">
172 TaskParameter="OutputProjectReferences"
173 ItemName="RestoreGraphProjectInputItems" />
174 </GetRestoreSolutionProjectsTask>
178 ============================================================
179 _FilterRestoreGraphProjectInputItems"
180 Filter out unsupported project entry points.
181 ============================================================
183 <Target Name="_FilterRestoreGraphProjectInputItems" DependsOnTargets="_LoadRestoreGraphEntryPoints"
184 Returns="@(FilteredRestoreGraphProjectInputItems)">
187 <RestoreProjectFilterMode Condition=" '$(RestoreProjectFilterMode)' == '' ">exclusionlist</RestoreProjectFilterMode>
190 <!-- Filter to a list of known supported types -->
191 <ItemGroup Condition=" '$(RestoreProjectFilterMode)' == 'inclusionlist' ">
192 <_FilteredRestoreGraphProjectInputItemsTmp
193 Include="@(RestoreGraphProjectInputItems)"
194 Condition=" '%(RestoreGraphProjectInputItems.Extension)' == '.csproj' Or
195 '%(RestoreGraphProjectInputItems.Extension)' == '.vbproj' Or
196 '%(RestoreGraphProjectInputItems.Extension)' == '.fsproj' Or
197 '%(RestoreGraphProjectInputItems.Extension)' == '.nuproj' Or
198 '%(RestoreGraphProjectInputItems.Extension)' == '.msbuildproj' Or
199 '%(RestoreGraphProjectInputItems.Extension)' == '.vcxproj' " />
202 <!-- Filter out disallowed types -->
203 <ItemGroup Condition=" '$(RestoreProjectFilterMode)' == 'exclusionlist' ">
204 <_FilteredRestoreGraphProjectInputItemsTmp
205 Include="@(RestoreGraphProjectInputItems)"
206 Condition=" '%(RestoreGraphProjectInputItems.Extension)' != '.metaproj'
207 AND '%(RestoreGraphProjectInputItems.Extension)' != '.shproj'
208 AND '%(RestoreGraphProjectInputItems.Extension)' != '.vcxitems'
209 AND '%(RestoreGraphProjectInputItems.Extension)' != '' " />
212 <!-- No filtering -->
213 <ItemGroup Condition=" '$(RestoreProjectFilterMode)' != 'exclusionlist' AND '$(RestoreProjectFilterMode)' != 'inclusionlist' ">
214 <_FilteredRestoreGraphProjectInputItemsTmp
215 Include="@(RestoreGraphProjectInputItems)" />
218 <!-- Remove duplicates -->
220 Inputs="@(_FilteredRestoreGraphProjectInputItemsTmp)">
222 TaskParameter="Filtered"
223 ItemName="FilteredRestoreGraphProjectInputItemsWithoutDuplicates" />
226 <!-- Remove projects that do not support restore. -->
228 Projects="@(FilteredRestoreGraphProjectInputItemsWithoutDuplicates)"
229 Targets="_IsProjectRestoreSupported"
230 ContinueOnError="$(RestoreContinueOnError)"
231 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
232 %(_MSBuildProjectReferenceExistent.SetPlatform);
233 $(_GenerateRestoreGraphProjectEntryInputProperties)"
234 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
237 TaskParameter="TargetOutputs"
238 ItemName="FilteredRestoreGraphProjectInputItems" />
241 <!-- Warn for projects that do not support restore. -->
242 <WarnForInvalidProjectsTask
243 Condition=" '$(DisableWarnForInvalidRestoreProjects)' != 'true' "
244 AllProjects="@(FilteredRestoreGraphProjectInputItemsWithoutDuplicates)"
245 ValidProjects="@(FilteredRestoreGraphProjectInputItems)" />
249 ============================================================
250 _GenerateRestoreGraph
251 Entry point for creating the project to project restore graph.
252 ============================================================
254 <Target Name="_GenerateRestoreGraph"
255 DependsOnTargets="_FilterRestoreGraphProjectInputItems;_GetAllRestoreProjectPathItems"
256 Returns="@(_RestoreGraphEntry)">
257 <Message Text="Generating dg file" Importance="low" />
258 <Message Text="%(_RestoreProjectPathItems.Identity)" Importance="low" />
260 <!-- Use all projects if RestoreRecursive is true. Otherwise use only the top level projects. -->
262 <_GenerateRestoreGraphProjectEntryInput Include="@(FilteredRestoreGraphProjectInputItems)" Condition=" '$(RestoreRecursive)' != 'true' " />
263 <_GenerateRestoreGraphProjectEntryInput Include="@(_RestoreProjectPathItems)" Condition=" '$(RestoreRecursive)' == 'true' " />
266 <!-- Process top level projects. -->
268 Projects="@(_GenerateRestoreGraphProjectEntryInput)"
269 Targets="_GenerateRestoreGraphProjectEntry"
270 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
271 %(_MSBuildProjectReferenceExistent.SetPlatform);
272 $(_GenerateRestoreGraphProjectEntryInputProperties)"
273 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
276 TaskParameter="TargetOutputs"
277 ItemName="_RestoreGraphEntry" />
280 <!-- Generate a spec for every project including dependencies. -->
282 Projects="@(_RestoreProjectPathItems)"
283 Targets="_GenerateProjectRestoreGraph"
284 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
285 %(_MSBuildProjectReferenceExistent.SetPlatform);
286 $(_GenerateRestoreGraphProjectEntryInputProperties)"
287 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
290 TaskParameter="TargetOutputs"
291 ItemName="_RestoreGraphEntry" />
296 ============================================================
297 _GenerateRestoreGraphProjectEntry
298 Top level entry point within a project.
299 ============================================================
301 <Target Name="_GenerateRestoreGraphProjectEntry"
302 DependsOnTargets="_GenerateRestoreSpecs;_GenerateDotnetCliToolReferenceSpecs"
303 Returns="@(_RestoreGraphEntry)">
304 <!-- Returns restore graph entries for the project and all dependencies -->
308 ============================================================
309 _GenerateRestoreSpecs
310 Mark entry points for restore.
311 ============================================================
313 <Target Name="_GenerateRestoreSpecs"
314 DependsOnTargets="_GetRestoreProjectStyle"
315 Returns="@(_RestoreGraphEntry)">
316 <Message Text="Restore entry point $(MSBuildProjectFullPath)" Importance="low" />
318 <!-- Mark entry point -->
319 <ItemGroup Condition=" '$(RestoreProjects)' == '' OR '$(RestoreProjects)' == 'true' ">
320 <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())" Condition=" '$(RestoreProjectStyle)' != 'Unknown' ">
321 <Type>RestoreSpec</Type>
322 <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
323 </_RestoreGraphEntry>
328 ============================================================
329 _GenerateDotnetCliToolReferenceSpecs
330 Collect DotnetCliToolReferences
331 ============================================================
333 <Target Name="_GenerateDotnetCliToolReferenceSpecs"
334 DependsOnTargets="_GetRestoreSettings"
335 Returns="@(_RestoreGraphEntry)">
338 <DotnetCliToolTargetFramework Condition=" '$(DotnetCliToolTargetFramework)' == '' ">netcoreapp1.0</DotnetCliToolTargetFramework>
341 <!-- Write out tool references -->
342 <GetRestoreDotnetCliToolsTask
343 Condition=" '$(RestoreDotnetCliToolReferences)' == '' OR '$(RestoreDotnetCliToolReferences)' == 'true' "
344 ProjectPath="$(MSBuildProjectFullPath)"
345 ToolFramework="$(DotnetCliToolTargetFramework)"
346 RestorePackagesPath="$(_OutputPackagesPath)"
347 RestoreFallbackFolders="$(_OutputFallbackFolders)"
348 RestoreSources="$(_OutputSources)"
349 RestoreConfigFilePaths="$(_OutputConfigFilePaths)"
350 DotnetCliToolReferences="@(DotnetCliToolReference)">
353 TaskParameter="RestoreGraphItems"
354 ItemName="_RestoreGraphEntry" />
355 </GetRestoreDotnetCliToolsTask>
360 ============================================================
362 Discover the project.json path if one exists for the project.
363 ============================================================
365 <Target Name="_GetProjectJsonPath"
366 Returns="$(_CurrentProjectJsonPath)">
367 <!-- Get project.json path -->
368 <!-- Skip this if the project style is already set. -->
369 <GetRestoreProjectJsonPathTask
370 ProjectPath="$(MSBuildProjectFullPath)"
371 Condition=" '$(RestoreProjectStyle)' == 'ProjectJson' OR '$(RestoreProjectStyle)' == '' ">
372 <Output TaskParameter="ProjectJsonPath" PropertyName="_CurrentProjectJsonPath" />
373 </GetRestoreProjectJsonPathTask>
377 ============================================================
378 _GetRestoreProjectStyle
379 Determine the project restore type.
380 ============================================================
382 <Target Name="_GetRestoreProjectStyle"
383 DependsOnTargets="_GetProjectJsonPath;CollectPackageReferences"
384 Returns="$(RestoreProjectStyle)">
385 <!-- This may be overridden by setting RestoreProjectStyle in the project. -->
387 <!-- If any PackageReferences exist treat it as PackageReference. This has priority over project.json. -->
388 <RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' AND @(PackageReference) != '' ">PackageReference</RestoreProjectStyle>
389 <!-- If this is not a PackageReference project check if project.json or projectName.project.json exists. -->
390 <RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' AND '$(_CurrentProjectJsonPath)' != '' ">ProjectJson</RestoreProjectStyle>
391 <!-- This project is either a packages.config project or one that does not use NuGet at all. -->
392 <RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' ">Unknown</RestoreProjectStyle>
397 ============================================================
398 _GetRestoreTargetFrameworksOutput
399 Read target frameworks from the project.
400 ============================================================
402 <Target Name="_GetRestoreTargetFrameworksOutput"
403 DependsOnTargets="_GetRestoreProjectStyle"
404 Returns="@(_RestoreTargetFrameworksOutputFiltered)">
407 <_RestoreProjectFramework></_RestoreProjectFramework>
410 <!-- For project.json projects target frameworks will be read from project.json. -->
411 <GetProjectTargetFrameworksTask
412 Condition=" '$(RestoreProjectStyle)' != 'ProjectJson' "
413 ProjectPath="$(MSBuildProjectFullPath)"
414 TargetFrameworks="$(TargetFrameworks)"
415 TargetFramework="$(TargetFramework)"
416 TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
417 TargetPlatformIdentifier="$(TargetPlatformIdentifier)"
418 TargetPlatformVersion="$(TargetPlatformVersion)"
419 TargetPlatformMinVersion="$(TargetPlatformMinVersion)">
421 TaskParameter="ProjectTargetFrameworks"
422 PropertyName="_RestoreProjectFramework" />
423 </GetProjectTargetFrameworksTask>
425 <ItemGroup Condition=" '$(_RestoreProjectFramework)' != '' ">
426 <_RestoreTargetFrameworksOutputFiltered Include="$(_RestoreProjectFramework.Split(';'))" />
431 ============================================================
432 _GetRestoreTargetFrameworksAsItems
433 Get the set of $(TargetFramework) and $(TargetFrameworks)
434 values that should be used for inner builds.
435 ============================================================
437 <Target Name="_GetRestoreTargetFrameworksAsItems"
438 DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksOutput"
439 Returns="@(_RestoreTargetFrameworkItems)">
442 <_RestoreTargetFrameworkItemsHasValues Condition=" '$(TargetFramework)' != '' OR '$(TargetFrameworks)' != '' ">true</_RestoreTargetFrameworkItemsHasValues>
445 <!-- Only return values for NETCore PackageReference projects -->
446 <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(_RestoreTargetFrameworkItemsHasValues)' == 'true' ">
447 <_RestoreTargetFrameworkItems Include="@(_RestoreTargetFrameworksOutputFiltered)" />
452 ============================================================
454 ============================================================
456 <Target Name="_GetRestoreSettings"
457 DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreSettingsOverrides;_GetRestoreTargetFrameworksAsItems"
458 Returns="$(_OutputSources);$(_OutputPackagesPath);$(_OutputFallbackFolders);$(_OutputConfigFilePaths)">
460 <!-- Read additional sources and fallback folders for each framework -->
462 Condition=" '$(RestoreProjectStyle)' == 'PackageReference' "
463 Projects="$(MSBuildProjectFullPath)"
464 Targets="_GetRestoreSettingsPerFramework"
465 Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity);
466 %(_MSBuildProjectReferenceExistent.SetConfiguration);
467 %(_MSBuildProjectReferenceExistent.SetPlatform);
468 $(_GenerateRestoreGraphProjectEntryInputProperties)"
469 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
472 TaskParameter="TargetOutputs"
473 ItemName="_RestoreSettingsPerFramework" />
476 <!-- For transitive project styles, we rely on evaluating all the settings and including them in the dg spec to faciliate no-op restore-->
477 <GetRestoreSettingsTask Condition=" '$(RestoreProjectStyle)' == 'PackageReference' OR '$(RestoreProjectStyle)' == 'ProjectJson' "
478 ProjectUniqueName="$(MSBuildProjectFullPath)"
479 RestoreSources="$(RestoreSources)"
480 RestorePackagesPath="$(RestorePackagesPath)"
481 RestoreFallbackFolders="$(RestoreFallbackFolders)"
482 RestoreConfigFile="$(RestoreConfigFile)"
483 RestoreSolutionDirectory="$(RestoreSolutionDirectory)"
484 RestoreSettingsPerFramework="@(_RestoreSettingsPerFramework)"
485 RestorePackagesPathOverride="$(_RestorePackagesPathOverride)"
486 RestoreSourcesOverride="$(_RestoreSourcesOverride)"
487 RestoreFallbackFoldersOverride="$(_RestoreFallbackFoldersOverride)"
488 MSBuildStartupDirectory="$(MSBuildStartupDirectory)">
490 TaskParameter="OutputSources"
491 PropertyName="_OutputSources" />
493 TaskParameter="OutputPackagesPath"
494 PropertyName="_OutputPackagesPath" />
496 TaskParameter="OutputFallbackFolders"
497 PropertyName="_OutputFallbackFolders" />
499 TaskParameter="OutputConfigFilePaths"
500 PropertyName="_OutputConfigFilePaths" />
501 </GetRestoreSettingsTask>
505 ============================================================
506 _GetRestoreSettingsPerFramework
507 Generate items with framework specific settings.
508 ============================================================
510 <Target Name="_GetRestoreSettingsPerFramework"
511 Returns="@(_RestoreSettingsPerFramework)">
514 <_RestoreSettingsPerFramework Include="$([System.Guid]::NewGuid())">
515 <RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
516 <RestoreAdditionalProjectFallbackFolders>$(RestoreAdditionalProjectFallbackFolders)</RestoreAdditionalProjectFallbackFolders>
517 <RestoreAdditionalProjectFallbackFoldersExcludes>$(RestoreAdditionalProjectFallbackFoldersExcludes)</RestoreAdditionalProjectFallbackFoldersExcludes>
518 </_RestoreSettingsPerFramework>
523 ============================================================
524 _GenerateRestoreProjectSpec
525 Generate a restore project spec for the current project.
526 ============================================================
528 <Target Name="_GenerateRestoreProjectSpec"
529 DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksOutput;_GetRestoreSettings"
530 Returns="@(_RestoreGraphEntry)">
532 <!-- Determine the restore output path -->
533 <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' OR '$(RestoreProjectStyle)' == 'ProjectJson' ">
534 <RestoreOutputPath Condition=" '$(RestoreOutputPath)' == '' " >$(BaseIntermediateOutputPath)</RestoreOutputPath>
537 <ConvertToAbsolutePath Paths="$(RestoreOutputPath)" Condition=" '$(RestoreProjectStyle)' == 'PackageReference' OR '$(RestoreProjectStyle)' == 'ProjectJson'">
538 <Output TaskParameter="AbsolutePaths" PropertyName="RestoreOutputAbsolutePath" />
539 </ConvertToAbsolutePath>
542 Determine project name for the assets file.
543 Highest priority: PackageId
544 If PackageId does not exist use: AssemblyName
545 If AssemblyName does not exist fallback to the project file name without the extension: $(MSBuildProjectName)
547 For non-NETCore projects use only: $(MSBuildProjectName)
550 <_RestoreProjectName>$(MSBuildProjectName)</_RestoreProjectName>
551 <_RestoreProjectName Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(AssemblyName)' != '' ">$(AssemblyName)</_RestoreProjectName>
552 <_RestoreProjectName Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(PackageId)' != '' ">$(PackageId)</_RestoreProjectName>
556 Determine project version for .NETCore projects
558 Use Version if it exists
559 Override with PackageVersion if it exists (same as pack)
561 <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' ">
562 <_RestoreProjectVersion>1.0.0</_RestoreProjectVersion>
563 <_RestoreProjectVersion Condition=" '$(Version)' != '' ">$(Version)</_RestoreProjectVersion>
564 <_RestoreProjectVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</_RestoreProjectVersion>
567 <!-- Determine if this will use cross targeting -->
568 <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(TargetFrameworks)' != '' ">
569 <_RestoreCrossTargeting>true</_RestoreCrossTargeting>
572 <!-- Determine if ContentFiles should be written by NuGet -->
573 <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(_RestoreSkipContentFileWrite)' == '' ">
574 <_RestoreSkipContentFileWrite Condition=" '$(TargetFrameworks)' == '' AND '$(TargetFramework)' == '' ">true</_RestoreSkipContentFileWrite>
577 <!-- Write properties for the top level entry point -->
578 <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' ">
579 <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
580 <Type>ProjectSpec</Type>
581 <Version>$(_RestoreProjectVersion)</Version>
582 <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
583 <ProjectPath>$(MSBuildProjectFullPath)</ProjectPath>
584 <ProjectName>$(_RestoreProjectName)</ProjectName>
585 <Sources>$(_OutputSources)</Sources>
586 <FallbackFolders>$(_OutputFallbackFolders)</FallbackFolders>
587 <PackagesPath>$(_OutputPackagesPath)</PackagesPath>
588 <ProjectStyle>$(RestoreProjectStyle)</ProjectStyle>
589 <OutputPath>$(RestoreOutputAbsolutePath)</OutputPath>
590 <TargetFrameworks>@(_RestoreTargetFrameworksOutputFiltered)</TargetFrameworks>
591 <RuntimeIdentifiers>$(RuntimeIdentifiers);$(RuntimeIdentifier)</RuntimeIdentifiers>
592 <RuntimeSupports>$(RuntimeSupports)</RuntimeSupports>
593 <CrossTargeting>$(_RestoreCrossTargeting)</CrossTargeting>
594 <RestoreLegacyPackagesDirectory>$(RestoreLegacyPackagesDirectory)</RestoreLegacyPackagesDirectory>
595 <ValidateRuntimeAssets>$(ValidateRuntimeIdentifierCompatibility)</ValidateRuntimeAssets>
596 <SkipContentFileWrite>$(_RestoreSkipContentFileWrite)</SkipContentFileWrite>
597 <ConfigFilePaths>$(_OutputConfigFilePaths)</ConfigFilePaths>
598 <TreatWarningsAsErrors>$(TreatWarningsAsErrors)</TreatWarningsAsErrors>
599 <WarningsAsErrors>$(WarningsAsErrors)</WarningsAsErrors>
600 <NoWarn>$(NoWarn)</NoWarn>
601 </_RestoreGraphEntry>
604 <!-- Use project.json -->
605 <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'ProjectJson' ">
606 <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
607 <Type>ProjectSpec</Type>
608 <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
609 <ProjectPath>$(MSBuildProjectFullPath)</ProjectPath>
610 <ProjectName>$(_RestoreProjectName)</ProjectName>
611 <Sources>$(_OutputSources)</Sources>
612 <OutputPath>$(RestoreOutputAbsolutePath)</OutputPath>
613 <FallbackFolders>$(_OutputFallbackFolders)</FallbackFolders>
614 <PackagesPath>$(_OutputPackagesPath)</PackagesPath>
615 <ProjectJsonPath>$(_CurrentProjectJsonPath)</ProjectJsonPath>
616 <ProjectStyle>$(RestoreProjectStyle)</ProjectStyle>
617 <ConfigFilePaths>$(_OutputConfigFilePaths)</ConfigFilePaths>
618 </_RestoreGraphEntry>
621 <!-- Non-NuGet type -->
622 <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'Unknown' ">
623 <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
624 <Type>ProjectSpec</Type>
625 <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
626 <ProjectPath>$(MSBuildProjectFullPath)</ProjectPath>
627 <ProjectName>$(_RestoreProjectName)</ProjectName>
628 <ProjectStyle>$(RestoreProjectStyle)</ProjectStyle>
629 <TargetFrameworks>@(_RestoreTargetFrameworksOutputFiltered)</TargetFrameworks>
630 </_RestoreGraphEntry>
635 ============================================================
636 _GenerateRestoreDependencies
637 Generate items for package and project references.
638 ============================================================
640 <Target Name="_GenerateRestoreDependencies"
641 DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksAsItems"
642 Returns="@(_RestoreGraphEntry)">
644 <!-- Get project and package references -->
645 <!-- Evaluate for each framework -->
647 Projects="$(MSBuildProjectFullPath)"
648 Targets="_GenerateProjectRestoreGraphPerFramework"
649 Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity);
650 %(_MSBuildProjectReferenceExistent.SetConfiguration);
651 %(_MSBuildProjectReferenceExistent.SetPlatform);
652 $(_GenerateRestoreGraphProjectEntryInputProperties)"
653 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
656 TaskParameter="TargetOutputs"
657 ItemName="_RestoreGraphEntry" />
662 ============================================================
663 _GenerateProjectRestoreGraph
664 Recursively walk project to project references.
665 ============================================================
667 <Target Name="_GenerateProjectRestoreGraph"
669 _GetRestoreProjectStyle;
670 _GetRestoreTargetFrameworksOutput;
671 _GenerateRestoreProjectSpec;
672 _GenerateRestoreDependencies"
673 Returns="@(_RestoreGraphEntry)">
675 <!-- Output from dependency targets -->
679 ============================================================
680 _GenerateProjectRestoreGraphPerFramework
681 Walk dependencies using $(TargetFramework)
682 ============================================================
684 <Target Name="_GenerateProjectRestoreGraphPerFramework"
685 DependsOnTargets="_GetRestoreProjectStyle;CollectPackageReferences"
686 Returns="@(_RestoreGraphEntry)">
688 <!-- Write out project references -->
689 <GetRestoreProjectReferencesTask
690 ProjectUniqueName="$(MSBuildProjectFullPath)"
691 ProjectReferences="@(ProjectReference)"
692 TargetFrameworks="$(TargetFramework)"
693 ParentProjectPath="$(MSBuildProjectFullPath)">
696 TaskParameter="RestoreGraphItems"
697 ItemName="_RestoreGraphEntry" />
698 </GetRestoreProjectReferencesTask>
700 <!-- Write out package references for NETCore -->
701 <GetRestorePackageReferencesTask
702 Condition=" '$(RestoreProjectStyle)' == 'PackageReference' "
703 ProjectUniqueName="$(MSBuildProjectFullPath)"
704 PackageReferences="@(PackageReference)"
705 TargetFrameworks="$(TargetFramework)">
708 TaskParameter="RestoreGraphItems"
709 ItemName="_RestoreGraphEntry" />
710 </GetRestorePackageReferencesTask>
713 <_CombinedFallbacks>$(PackageTargetFallback);$(AssetTargetFallback)</_CombinedFallbacks>
716 <!-- Write out target framework information -->
717 <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(_CombinedFallbacks)' != '' ">
718 <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
719 <Type>TargetFrameworkInformation</Type>
720 <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
721 <PackageTargetFallback>$(PackageTargetFallback)</PackageTargetFallback>
722 <AssetTargetFallback>$(AssetTargetFallback)</AssetTargetFallback>
723 <TargetFramework>$(TargetFramework)</TargetFramework>
724 </_RestoreGraphEntry>
729 ============================================================
730 _GenerateRestoreProjectPathItemsPerFramework
731 Get absolute paths for all project references.
732 ============================================================
734 <Target Name="_GenerateRestoreProjectPathItemsPerFramework"
735 Returns="@(_RestoreProjectPathItems)">
737 <!-- Get the absolute paths to all projects -->
738 <ConvertToAbsolutePath Paths="@(ProjectReference)">
739 <Output TaskParameter="AbsolutePaths" PropertyName="_RestoreGraphAbsoluteProjectPaths" />
740 </ConvertToAbsolutePath>
743 <_RestoreProjectPathItems Include="$(_RestoreGraphAbsoluteProjectPaths)" />
748 ============================================================
749 _GenerateRestoreProjectPathItems
750 Get all project references regardless of framework
751 ============================================================
753 <Target Name="_GenerateRestoreProjectPathItems"
754 DependsOnTargets="_GetRestoreTargetFrameworksOutput;_GetRestoreTargetFrameworksAsItems"
755 Returns="@(_CurrentRestoreProjectPathItems)">
757 <!-- Get all project references for the current project -->
759 Projects="$(MSBuildProjectFullPath)"
760 Targets="_GenerateRestoreProjectPathItemsPerFramework"
761 ContinueOnError="$(RestoreContinueOnError)"
762 Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity);
763 %(_MSBuildProjectReferenceExistent.SetConfiguration);
764 %(_MSBuildProjectReferenceExistent.SetPlatform);
765 $(_GenerateRestoreGraphProjectEntryInputProperties)"
766 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
769 TaskParameter="TargetOutputs"
770 ItemName="_CurrentRestoreProjectPathItemsOutputs" />
773 <!-- Drop any duplicate items -->
775 Inputs="@(_CurrentRestoreProjectPathItemsOutputs)">
777 TaskParameter="Filtered"
778 ItemName="_CurrentRestoreProjectPathItems" />
783 ============================================================
784 _GenerateRestoreProjectPathWalk
785 Recursively walk projects
786 ============================================================
788 <Target Name="_GenerateRestoreProjectPathWalk"
789 DependsOnTargets="_GenerateRestoreProjectPathItems;_GetRestoreTargetFrameworksAsItems"
790 Returns="@(_RestoreProjectPathItems)">
792 <!-- Walk project references -->
794 Projects="@(_CurrentRestoreProjectPathItems)"
795 Targets="_GenerateRestoreProjectPathWalk"
796 ContinueOnError="$(RestoreContinueOnError)"
797 Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity);
798 %(_MSBuildProjectReferenceExistent.SetConfiguration);
799 %(_MSBuildProjectReferenceExistent.SetPlatform);
800 $(_GenerateRestoreGraphProjectEntryInputProperties)"
801 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
804 TaskParameter="TargetOutputs"
805 ItemName="_GenerateRestoreProjectPathWalkOutputs" />
808 <!-- Include the current project in the result -->
810 <_GenerateRestoreProjectPathWalkOutputs Include="$(MSBuildProjectFullPath)" />
813 <!-- Remove duplicates -->
815 Inputs="@(_GenerateRestoreProjectPathWalkOutputs)">
817 TaskParameter="Filtered"
818 ItemName="_RestoreProjectPathItems" />
823 ============================================================
824 _GetAllRestoreProjectPathItems
825 Get the full list of known projects.
826 This includes all child projects from all target frameworks.
827 ============================================================
829 <Target Name="_GetAllRestoreProjectPathItems"
830 DependsOnTargets="_FilterRestoreGraphProjectInputItems"
831 Returns="@(_RestoreProjectPathItems)">
833 <!-- Walk projects -->
835 Projects="@(FilteredRestoreGraphProjectInputItems)"
836 Targets="_GenerateRestoreProjectPathWalk"
837 ContinueOnError="$(RestoreContinueOnError)"
838 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
839 %(_MSBuildProjectReferenceExistent.SetPlatform);
840 $(_GenerateRestoreGraphProjectEntryInputProperties)"
841 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
844 TaskParameter="TargetOutputs"
845 ItemName="_RestoreProjectPathItemsOutputs" />
848 <!-- Remove duplicates -->
850 Inputs="@(_RestoreProjectPathItemsOutputs)">
852 TaskParameter="Filtered"
853 ItemName="_RestoreProjectPathItemsWithoutDupes" />
856 <!-- Remove projects that do not support restore. -->
858 Projects="@(_RestoreProjectPathItemsWithoutDupes)"
859 Targets="_IsProjectRestoreSupported"
860 ContinueOnError="$(RestoreContinueOnError)"
861 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
862 %(_MSBuildProjectReferenceExistent.SetPlatform);
863 $(_GenerateRestoreGraphProjectEntryInputProperties)"
864 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
867 TaskParameter="TargetOutputs"
868 ItemName="_RestoreProjectPathItems" />
873 ============================================================
874 _GetRestoreSettingsOverrides
875 Get global property overrides that should be resolved
876 against the current working directory instead of the project.
877 This is done by calling into NuGet.targets in a new scope,
878 project properties will not be returned by the calls below.
879 ============================================================
881 <Target Name="_GetRestoreSettingsOverrides"
882 Returns="$(_RestorePackagesPathOverride);$(_RestoreSourcesOverride);$(_RestoreFallbackFoldersOverride)">
884 <!-- RestorePackagesPathOverride -->
886 Condition=" '$(RestorePackagesPath)' != '' "
887 Projects="$(MSBuildThisFileFullPath)"
888 Targets="_GetRestorePackagesPathOverride"
889 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
890 %(_MSBuildProjectReferenceExistent.SetPlatform);"
891 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
894 TaskParameter="TargetOutputs"
895 PropertyName="_RestorePackagesPathOverride" />
898 <!-- RestoreSourcesOverride -->
900 Condition=" '$(RestoreSources)' != '' "
901 Projects="$(MSBuildThisFileFullPath)"
902 Targets="_GetRestoreSourcesOverride"
903 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
904 %(_MSBuildProjectReferenceExistent.SetPlatform);"
905 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
908 TaskParameter="TargetOutputs"
909 PropertyName="_RestoreSourcesOverride" />
912 <!-- RestoreFallbackFoldersOverride -->
914 Condition=" '$(RestoreFallbackFolders)' != '' "
915 Projects="$(MSBuildThisFileFullPath)"
916 Targets="_GetRestoreFallbackFoldersOverride"
917 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
918 %(_MSBuildProjectReferenceExistent.SetPlatform);"
919 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
922 TaskParameter="TargetOutputs"
923 PropertyName="_RestoreFallbackFoldersOverride" />
928 ============================================================
929 _GetRestorePackagesPathOverride
930 ============================================================
932 <Target Name="_GetRestorePackagesPathOverride"
933 Returns="$(_RestorePackagesPathOverride)">
935 <_RestorePackagesPathOverride>$(RestorePackagesPath)</_RestorePackagesPathOverride>
940 ============================================================
941 _GetRestoreSourcesOverride
942 ============================================================
944 <Target Name="_GetRestoreSourcesOverride"
945 Returns="$(_RestoreSourcesOverride)">
947 <_RestoreSourcesOverride>$(RestoreSources)</_RestoreSourcesOverride>
952 ============================================================
953 _GetRestoreFallbackFoldersOverride
954 ============================================================
956 <Target Name="_GetRestoreFallbackFoldersOverride"
957 Returns="$(_RestoreFallbackFoldersOverride)">
959 <_RestoreFallbackFoldersOverride>$(RestoreFallbackFolders)</_RestoreFallbackFoldersOverride>
964 ============================================================
965 _IsProjectRestoreSupported
966 Verify restore targets exist in the project.
967 ============================================================
969 <Target Name="_IsProjectRestoreSupported"
970 Returns="@(_ValidProjectsForRestore)">
973 <_ValidProjectsForRestore Include="$(MSBuildProjectFullPath)" />