diff options
Diffstat (limited to 'Tools/dotnetcli/sdk/2.1.2/NuGet.targets')
-rw-r--r-- | Tools/dotnetcli/sdk/2.1.2/NuGet.targets | 977 |
1 files changed, 977 insertions, 0 deletions
diff --git a/Tools/dotnetcli/sdk/2.1.2/NuGet.targets b/Tools/dotnetcli/sdk/2.1.2/NuGet.targets new file mode 100644 index 0000000000..3e0a3b87fb --- /dev/null +++ b/Tools/dotnetcli/sdk/2.1.2/NuGet.targets @@ -0,0 +1,977 @@ +<!-- +*********************************************************************************************** +NuGet.targets + +WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have + created a backup copy. Incorrect changes to this file will make it + impossible to load or build your projects from the command-line or the IDE. + +Copyright (c) .NET Foundation. All rights reserved. +*********************************************************************************************** + + This target file contains the NuGet Restore target for walking the project and reference graph + and restoring dependencies from the graph. + + Ways to use this targets file: + 1. Invoke it directly and provide project file paths using $(RestoreGraphProjectInput). + 2. With a solution this may be used as a target in the metaproj. + 3. Import the targets file from a project. + + Restore flow summary: + 1. Top level projects (entry points) are determined. + 2. Each project and all of its project references are walked recursively. + 3. The project is evaluated for each $(TargetFramework). Items are created + for project properties and dependencies. Each item is marked + with the project it came from so that it can be matched up later. + 4. All restore items generated by the walk are grouped together by + project and convert into a project spec. + + The result file contains: + 1. A list of projects to restore. + 2. The complete closure of all projects referenced (Includes project references that are not being restored directly). + 3. Package and project dependencies for each project. + 4. DotnetCliTool references + --> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <!-- Mark that this target file has been loaded. --> + <IsRestoreTargetsFileLoaded>true</IsRestoreTargetsFileLoaded> + <!-- Load NuGet.Build.Tasks.dll, this can be overridden to use a different version with $(RestoreTaskAssemblyFile) --> + <RestoreTaskAssemblyFile Condition=" '$(RestoreTaskAssemblyFile)' == '' ">NuGet.Build.Tasks.dll</RestoreTaskAssemblyFile> + <!-- Do not hide errors and warnings by default --> + <HideWarningsAndErrors Condition=" '$(HideWarningsAndErrors)' == '' ">false</HideWarningsAndErrors> + <!-- Recurse by default --> + <RestoreRecursive Condition=" '$(RestoreRecursive)' == '' ">true</RestoreRecursive> + <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> + <!-- RuntimeIdentifier compatibility check --> + <ValidateRuntimeIdentifierCompatibility Condition=" '$(ValidateRuntimeIdentifierCompatibility)' == '' ">false</ValidateRuntimeIdentifierCompatibility> + <!-- Error handling while walking projects --> + <RestoreContinueOnError Condition=" '$(RestoreContinueOnError)' == '' ">WarnAndContinue</RestoreContinueOnError> + </PropertyGroup> + + <PropertyGroup> + <!-- Generate a restore graph for each entry point project. --> + <_GenerateRestoreGraphProjectEntryInputProperties> + RestoreUseCustomAfterTargets=$(RestoreUseCustomAfterTargets); + NuGetRestoreTargets=$(MSBuildThisFileFullPath); + BuildProjectReferences=false; + ExcludeRestorePackageImports=true; + </_GenerateRestoreGraphProjectEntryInputProperties> + + <!-- Standalone mode + This is used by NuGet.exe to inject targets into the project that will be + walked next. In normal /t:Restore mode this causes a duplicate import + since NuGet.targets it loaded as part of MSBuild, there is should be + skipped. --> + <_GenerateRestoreGraphProjectEntryInputProperties Condition=" '$(RestoreUseCustomAfterTargets)' == 'true' "> + $(_GenerateRestoreGraphProjectEntryInputProperties); + CustomAfterMicrosoftCommonCrossTargetingTargets=$(MSBuildThisFileFullPath); + CustomAfterMicrosoftCommonTargets=$(MSBuildThisFileFullPath); + </_GenerateRestoreGraphProjectEntryInputProperties> + </PropertyGroup> + + <!-- Tasks --> + <UsingTask TaskName="NuGet.Build.Tasks.RestoreTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.WriteRestoreGraphTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreProjectJsonPathTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreProjectReferencesTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetRestorePackageReferencesTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreDotnetCliToolsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetProjectTargetFrameworksTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreSolutionProjectsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetRestoreSettingsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.WarnForInvalidProjectsTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + <UsingTask TaskName="NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask" AssemblyFile="$(RestoreTaskAssemblyFile)" /> + + <!-- + ============================================================ + Restore + Main entry point for restoring packages + ============================================================ + --> + <Target Name="Restore" DependsOnTargets="_GenerateRestoreGraph"> + + <!-- Drop any duplicate items --> + <RemoveDuplicates + Inputs="@(_RestoreGraphEntry)"> + <Output + TaskParameter="Filtered" + ItemName="_RestoreGraphEntryFiltered" /> + </RemoveDuplicates> + + <!-- Call restore --> + <RestoreTask + RestoreGraphItems="@(_RestoreGraphEntryFiltered)" + RestoreDisableParallel="$(RestoreDisableParallel)" + RestoreNoCache="$(RestoreNoCache)" + RestoreIgnoreFailedSources="$(RestoreIgnoreFailedSources)" + RestoreRecursive="$(RestoreRecursive)" + RestoreForce="$(RestoreForce)" + HideWarningsAndErrors="$(HideWarningsAndErrors)"/> + </Target> + + <!-- + ============================================================ + GenerateRestoreGraphFile + Writes the output of _GenerateRestoreGraph to disk + ============================================================ + --> + <Target Name="GenerateRestoreGraphFile" DependsOnTargets="_GenerateRestoreGraph"> + <!-- Validate --> + <Error Condition="$(RestoreGraphOutputPath) == ''" Text="Missing RestoreGraphOutputPath property!" /> + + <!-- Drop any duplicate items --> + <RemoveDuplicates + Inputs="@(_RestoreGraphEntry)"> + <Output + TaskParameter="Filtered" + ItemName="_RestoreGraphEntryFiltered" /> + </RemoveDuplicates> + + <!-- Write file --> + <WriteRestoreGraphTask + RestoreGraphItems="@(_RestoreGraphEntryFiltered)" + RestoreGraphOutputPath="$(RestoreGraphOutputPath)" + RestoreRecursive="$(RestoreRecursive)" /> + </Target> + + <!-- + ============================================================ + CollectPackageReferences + Gathers all PackageReference items from the project. + This target may be used as an extension point to modify + package references before NuGet reads them. + ============================================================ + --> + <Target Name="CollectPackageReferences" Returns="@(PackageReference)" /> + + <!-- + ============================================================ + _LoadRestoreGraphEntryPoints + Find project entry points and load them into items. + ============================================================ + --> + <Target Name="_LoadRestoreGraphEntryPoints" Returns="@(RestoreGraphProjectInputItems)"> + + <!-- Allow overriding items with RestoreGraphProjectInput --> + <ItemGroup Condition=" @(RestoreGraphProjectInputItems) == '' "> + <RestoreGraphProjectInputItems Include="$(RestoreGraphProjectInput)" /> + </ItemGroup> + + <!-- Project case --> + <ItemGroup Condition=" $(MSBuildProjectFullPath.EndsWith('.metaproj')) != 'true' AND @(RestoreGraphProjectInputItems) == '' "> + <RestoreGraphProjectInputItems Include="$(MSBuildProjectFullPath)" /> + </ItemGroup> + + <!-- Solution case --> + <GetRestoreSolutionProjectsTask + Condition=" $(MSBuildProjectFullPath.EndsWith('.metaproj')) == 'true' AND @(RestoreGraphProjectInputItems) == '' " + ProjectReferences="@(ProjectReference)" + SolutionFilePath="$(MSBuildProjectFullPath)"> + <Output + TaskParameter="OutputProjectReferences" + ItemName="RestoreGraphProjectInputItems" /> + </GetRestoreSolutionProjectsTask> + </Target> + + <!-- + ============================================================ + _FilterRestoreGraphProjectInputItems" + Filter out unsupported project entry points. + ============================================================ + --> + <Target Name="_FilterRestoreGraphProjectInputItems" DependsOnTargets="_LoadRestoreGraphEntryPoints" + Returns="@(FilteredRestoreGraphProjectInputItems)"> + + <PropertyGroup> + <RestoreProjectFilterMode Condition=" '$(RestoreProjectFilterMode)' == '' ">exclusionlist</RestoreProjectFilterMode> + </PropertyGroup> + + <!-- Filter to a list of known supported types --> + <ItemGroup Condition=" '$(RestoreProjectFilterMode)' == 'inclusionlist' "> + <_FilteredRestoreGraphProjectInputItemsTmp + Include="@(RestoreGraphProjectInputItems)" + Condition=" '%(RestoreGraphProjectInputItems.Extension)' == '.csproj' Or + '%(RestoreGraphProjectInputItems.Extension)' == '.vbproj' Or + '%(RestoreGraphProjectInputItems.Extension)' == '.fsproj' Or + '%(RestoreGraphProjectInputItems.Extension)' == '.nuproj' Or + '%(RestoreGraphProjectInputItems.Extension)' == '.msbuildproj' Or + '%(RestoreGraphProjectInputItems.Extension)' == '.vcxproj' " /> + </ItemGroup> + + <!-- Filter out disallowed types --> + <ItemGroup Condition=" '$(RestoreProjectFilterMode)' == 'exclusionlist' "> + <_FilteredRestoreGraphProjectInputItemsTmp + Include="@(RestoreGraphProjectInputItems)" + Condition=" '%(RestoreGraphProjectInputItems.Extension)' != '.metaproj' + AND '%(RestoreGraphProjectInputItems.Extension)' != '.shproj' + AND '%(RestoreGraphProjectInputItems.Extension)' != '.vcxitems' + AND '%(RestoreGraphProjectInputItems.Extension)' != '' " /> + </ItemGroup> + + <!-- No filtering --> + <ItemGroup Condition=" '$(RestoreProjectFilterMode)' != 'exclusionlist' AND '$(RestoreProjectFilterMode)' != 'inclusionlist' "> + <_FilteredRestoreGraphProjectInputItemsTmp + Include="@(RestoreGraphProjectInputItems)" /> + </ItemGroup> + + <!-- Remove duplicates --> + <RemoveDuplicates + Inputs="@(_FilteredRestoreGraphProjectInputItemsTmp)"> + <Output + TaskParameter="Filtered" + ItemName="FilteredRestoreGraphProjectInputItemsWithoutDuplicates" /> + </RemoveDuplicates> + + <!-- Remove projects that do not support restore. --> + <MsBuild + Projects="@(FilteredRestoreGraphProjectInputItemsWithoutDuplicates)" + Targets="_IsProjectRestoreSupported" + ContinueOnError="$(RestoreContinueOnError)" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="FilteredRestoreGraphProjectInputItems" /> + </MsBuild> + + <!-- Warn for projects that do not support restore. --> + <WarnForInvalidProjectsTask + Condition=" '$(DisableWarnForInvalidRestoreProjects)' != 'true' " + AllProjects="@(FilteredRestoreGraphProjectInputItemsWithoutDuplicates)" + ValidProjects="@(FilteredRestoreGraphProjectInputItems)" /> + </Target> + + <!-- + ============================================================ + _GenerateRestoreGraph + Entry point for creating the project to project restore graph. + ============================================================ + --> + <Target Name="_GenerateRestoreGraph" + DependsOnTargets="_FilterRestoreGraphProjectInputItems;_GetAllRestoreProjectPathItems" + Returns="@(_RestoreGraphEntry)"> + <Message Text="Generating dg file" Importance="low" /> + <Message Text="%(_RestoreProjectPathItems.Identity)" Importance="low" /> + + <!-- Use all projects if RestoreRecursive is true. Otherwise use only the top level projects. --> + <ItemGroup> + <_GenerateRestoreGraphProjectEntryInput Include="@(FilteredRestoreGraphProjectInputItems)" Condition=" '$(RestoreRecursive)' != 'true' " /> + <_GenerateRestoreGraphProjectEntryInput Include="@(_RestoreProjectPathItems)" Condition=" '$(RestoreRecursive)' == 'true' " /> + </ItemGroup> + + <!-- Process top level projects. --> + <MsBuild + Projects="@(_GenerateRestoreGraphProjectEntryInput)" + Targets="_GenerateRestoreGraphProjectEntry" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_RestoreGraphEntry" /> + </MsBuild> + + <!-- Generate a spec for every project including dependencies. --> + <MsBuild + Projects="@(_RestoreProjectPathItems)" + Targets="_GenerateProjectRestoreGraph" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_RestoreGraphEntry" /> + </MsBuild> + </Target> + + <!-- + ============================================================ + _GenerateRestoreGraphProjectEntry + Top level entry point within a project. + ============================================================ + --> + <Target Name="_GenerateRestoreGraphProjectEntry" + DependsOnTargets="_GenerateRestoreSpecs;_GenerateDotnetCliToolReferenceSpecs" + Returns="@(_RestoreGraphEntry)"> + <!-- Returns restore graph entries for the project and all dependencies --> + </Target> + + <!-- + ============================================================ + _GenerateRestoreSpecs + Mark entry points for restore. + ============================================================ + --> + <Target Name="_GenerateRestoreSpecs" + DependsOnTargets="_GetRestoreProjectStyle" + Returns="@(_RestoreGraphEntry)"> + <Message Text="Restore entry point $(MSBuildProjectFullPath)" Importance="low" /> + + <!-- Mark entry point --> + <ItemGroup Condition=" '$(RestoreProjects)' == '' OR '$(RestoreProjects)' == 'true' "> + <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())" Condition=" '$(RestoreProjectStyle)' != 'Unknown' "> + <Type>RestoreSpec</Type> + <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName> + </_RestoreGraphEntry> + </ItemGroup> + </Target> + + <!-- + ============================================================ + _GenerateDotnetCliToolReferenceSpecs + Collect DotnetCliToolReferences + ============================================================ + --> + <Target Name="_GenerateDotnetCliToolReferenceSpecs" + DependsOnTargets="_GetRestoreSettings" + Returns="@(_RestoreGraphEntry)"> + + <PropertyGroup> + <DotnetCliToolTargetFramework Condition=" '$(DotnetCliToolTargetFramework)' == '' ">netcoreapp1.0</DotnetCliToolTargetFramework> + </PropertyGroup> + + <!-- Write out tool references --> + <GetRestoreDotnetCliToolsTask + Condition=" '$(RestoreDotnetCliToolReferences)' == '' OR '$(RestoreDotnetCliToolReferences)' == 'true' " + ProjectPath="$(MSBuildProjectFullPath)" + ToolFramework="$(DotnetCliToolTargetFramework)" + RestorePackagesPath="$(_OutputPackagesPath)" + RestoreFallbackFolders="$(_OutputFallbackFolders)" + RestoreSources="$(_OutputSources)" + RestoreConfigFilePaths="$(_OutputConfigFilePaths)" + DotnetCliToolReferences="@(DotnetCliToolReference)"> + + <Output + TaskParameter="RestoreGraphItems" + ItemName="_RestoreGraphEntry" /> + </GetRestoreDotnetCliToolsTask> + + </Target> + + <!-- + ============================================================ + _GetProjectJsonPath + Discover the project.json path if one exists for the project. + ============================================================ + --> + <Target Name="_GetProjectJsonPath" + Returns="$(_CurrentProjectJsonPath)"> + <!-- Get project.json path --> + <!-- Skip this if the project style is already set. --> + <GetRestoreProjectJsonPathTask + ProjectPath="$(MSBuildProjectFullPath)" + Condition=" '$(RestoreProjectStyle)' == 'ProjectJson' OR '$(RestoreProjectStyle)' == '' "> + <Output TaskParameter="ProjectJsonPath" PropertyName="_CurrentProjectJsonPath" /> + </GetRestoreProjectJsonPathTask> + </Target> + + <!-- + ============================================================ + _GetRestoreProjectStyle + Determine the project restore type. + ============================================================ + --> + <Target Name="_GetRestoreProjectStyle" + DependsOnTargets="_GetProjectJsonPath;CollectPackageReferences" + Returns="$(RestoreProjectStyle)"> + <!-- This may be overridden by setting RestoreProjectStyle in the project. --> + <PropertyGroup> + <!-- If any PackageReferences exist treat it as PackageReference. This has priority over project.json. --> + <RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' AND @(PackageReference) != '' ">PackageReference</RestoreProjectStyle> + <!-- If this is not a PackageReference project check if project.json or projectName.project.json exists. --> + <RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' AND '$(_CurrentProjectJsonPath)' != '' ">ProjectJson</RestoreProjectStyle> + <!-- This project is either a packages.config project or one that does not use NuGet at all. --> + <RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' ">Unknown</RestoreProjectStyle> + </PropertyGroup> + </Target> + + <!-- + ============================================================ + _GetRestoreTargetFrameworksOutput + Read target frameworks from the project. + ============================================================ + --> + <Target Name="_GetRestoreTargetFrameworksOutput" + DependsOnTargets="_GetRestoreProjectStyle" + Returns="@(_RestoreTargetFrameworksOutputFiltered)"> + + <PropertyGroup> + <_RestoreProjectFramework></_RestoreProjectFramework> + </PropertyGroup> + + <!-- For project.json projects target frameworks will be read from project.json. --> + <GetProjectTargetFrameworksTask + Condition=" '$(RestoreProjectStyle)' != 'ProjectJson' " + ProjectPath="$(MSBuildProjectFullPath)" + TargetFrameworks="$(TargetFrameworks)" + TargetFramework="$(TargetFramework)" + TargetFrameworkMoniker="$(TargetFrameworkMoniker)" + TargetPlatformIdentifier="$(TargetPlatformIdentifier)" + TargetPlatformVersion="$(TargetPlatformVersion)" + TargetPlatformMinVersion="$(TargetPlatformMinVersion)"> + <Output + TaskParameter="ProjectTargetFrameworks" + PropertyName="_RestoreProjectFramework" /> + </GetProjectTargetFrameworksTask> + + <ItemGroup Condition=" '$(_RestoreProjectFramework)' != '' "> + <_RestoreTargetFrameworksOutputFiltered Include="$(_RestoreProjectFramework.Split(';'))" /> + </ItemGroup> + </Target> + + <!-- + ============================================================ + _GetRestoreTargetFrameworksAsItems + Get the set of $(TargetFramework) and $(TargetFrameworks) + values that should be used for inner builds. + ============================================================ + --> + <Target Name="_GetRestoreTargetFrameworksAsItems" + DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksOutput" + Returns="@(_RestoreTargetFrameworkItems)"> + + <PropertyGroup> + <_RestoreTargetFrameworkItemsHasValues Condition=" '$(TargetFramework)' != '' OR '$(TargetFrameworks)' != '' ">true</_RestoreTargetFrameworkItemsHasValues> + </PropertyGroup> + + <!-- Only return values for NETCore PackageReference projects --> + <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(_RestoreTargetFrameworkItemsHasValues)' == 'true' "> + <_RestoreTargetFrameworkItems Include="@(_RestoreTargetFrameworksOutputFiltered)" /> + </ItemGroup> + </Target> + + <!-- + ============================================================ + _GetRestoreSettings + ============================================================ + --> + <Target Name="_GetRestoreSettings" + DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreSettingsOverrides;_GetRestoreTargetFrameworksAsItems" + Returns="$(_OutputSources);$(_OutputPackagesPath);$(_OutputFallbackFolders);$(_OutputConfigFilePaths)"> + + <!-- Read additional sources and fallback folders for each framework --> + <MSBuild + Condition=" '$(RestoreProjectStyle)' == 'PackageReference' " + Projects="$(MSBuildProjectFullPath)" + Targets="_GetRestoreSettingsPerFramework" + Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity); + %(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_RestoreSettingsPerFramework" /> + </MSBuild> + + <!-- For transitive project styles, we rely on evaluating all the settings and including them in the dg spec to faciliate no-op restore--> + <GetRestoreSettingsTask Condition=" '$(RestoreProjectStyle)' == 'PackageReference' OR '$(RestoreProjectStyle)' == 'ProjectJson' " + ProjectUniqueName="$(MSBuildProjectFullPath)" + RestoreSources="$(RestoreSources)" + RestorePackagesPath="$(RestorePackagesPath)" + RestoreFallbackFolders="$(RestoreFallbackFolders)" + RestoreConfigFile="$(RestoreConfigFile)" + RestoreSolutionDirectory="$(RestoreSolutionDirectory)" + RestoreSettingsPerFramework="@(_RestoreSettingsPerFramework)" + RestorePackagesPathOverride="$(_RestorePackagesPathOverride)" + RestoreSourcesOverride="$(_RestoreSourcesOverride)" + RestoreFallbackFoldersOverride="$(_RestoreFallbackFoldersOverride)" + MSBuildStartupDirectory="$(MSBuildStartupDirectory)"> + <Output + TaskParameter="OutputSources" + PropertyName="_OutputSources" /> + <Output + TaskParameter="OutputPackagesPath" + PropertyName="_OutputPackagesPath" /> + <Output + TaskParameter="OutputFallbackFolders" + PropertyName="_OutputFallbackFolders" /> + <Output + TaskParameter="OutputConfigFilePaths" + PropertyName="_OutputConfigFilePaths" /> + </GetRestoreSettingsTask> + </Target> + + <!-- + ============================================================ + _GetRestoreSettingsPerFramework + Generate items with framework specific settings. + ============================================================ + --> + <Target Name="_GetRestoreSettingsPerFramework" + Returns="@(_RestoreSettingsPerFramework)"> + + <ItemGroup> + <_RestoreSettingsPerFramework Include="$([System.Guid]::NewGuid())"> + <RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources> + <RestoreAdditionalProjectFallbackFolders>$(RestoreAdditionalProjectFallbackFolders)</RestoreAdditionalProjectFallbackFolders> + <RestoreAdditionalProjectFallbackFoldersExcludes>$(RestoreAdditionalProjectFallbackFoldersExcludes)</RestoreAdditionalProjectFallbackFoldersExcludes> + </_RestoreSettingsPerFramework> + </ItemGroup> + </Target> + + <!-- + ============================================================ + _GenerateRestoreProjectSpec + Generate a restore project spec for the current project. + ============================================================ + --> + <Target Name="_GenerateRestoreProjectSpec" + DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksOutput;_GetRestoreSettings" + Returns="@(_RestoreGraphEntry)"> + + <!-- Determine the restore output path --> + <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' OR '$(RestoreProjectStyle)' == 'ProjectJson' "> + <RestoreOutputPath Condition=" '$(RestoreOutputPath)' == '' " >$(BaseIntermediateOutputPath)</RestoreOutputPath> + </PropertyGroup> + + <ConvertToAbsolutePath Paths="$(RestoreOutputPath)" Condition=" '$(RestoreProjectStyle)' == 'PackageReference' OR '$(RestoreProjectStyle)' == 'ProjectJson'"> + <Output TaskParameter="AbsolutePaths" PropertyName="RestoreOutputAbsolutePath" /> + </ConvertToAbsolutePath> + + <!-- + Determine project name for the assets file. + Highest priority: PackageId + If PackageId does not exist use: AssemblyName + If AssemblyName does not exist fallback to the project file name without the extension: $(MSBuildProjectName) + + For non-NETCore projects use only: $(MSBuildProjectName) + --> + <PropertyGroup> + <_RestoreProjectName>$(MSBuildProjectName)</_RestoreProjectName> + <_RestoreProjectName Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(AssemblyName)' != '' ">$(AssemblyName)</_RestoreProjectName> + <_RestoreProjectName Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(PackageId)' != '' ">$(PackageId)</_RestoreProjectName> + </PropertyGroup> + + <!-- + Determine project version for .NETCore projects + Default to 1.0.0 + Use Version if it exists + Override with PackageVersion if it exists (same as pack) + --> + <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' "> + <_RestoreProjectVersion>1.0.0</_RestoreProjectVersion> + <_RestoreProjectVersion Condition=" '$(Version)' != '' ">$(Version)</_RestoreProjectVersion> + <_RestoreProjectVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</_RestoreProjectVersion> + </PropertyGroup> + + <!-- Determine if this will use cross targeting --> + <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(TargetFrameworks)' != '' "> + <_RestoreCrossTargeting>true</_RestoreCrossTargeting> + </PropertyGroup> + + <!-- Determine if ContentFiles should be written by NuGet --> + <PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(_RestoreSkipContentFileWrite)' == '' "> + <_RestoreSkipContentFileWrite Condition=" '$(TargetFrameworks)' == '' AND '$(TargetFramework)' == '' ">true</_RestoreSkipContentFileWrite> + </PropertyGroup> + + <!-- Write properties for the top level entry point --> + <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' "> + <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())"> + <Type>ProjectSpec</Type> + <Version>$(_RestoreProjectVersion)</Version> + <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName> + <ProjectPath>$(MSBuildProjectFullPath)</ProjectPath> + <ProjectName>$(_RestoreProjectName)</ProjectName> + <Sources>$(_OutputSources)</Sources> + <FallbackFolders>$(_OutputFallbackFolders)</FallbackFolders> + <PackagesPath>$(_OutputPackagesPath)</PackagesPath> + <ProjectStyle>$(RestoreProjectStyle)</ProjectStyle> + <OutputPath>$(RestoreOutputAbsolutePath)</OutputPath> + <TargetFrameworks>@(_RestoreTargetFrameworksOutputFiltered)</TargetFrameworks> + <RuntimeIdentifiers>$(RuntimeIdentifiers);$(RuntimeIdentifier)</RuntimeIdentifiers> + <RuntimeSupports>$(RuntimeSupports)</RuntimeSupports> + <CrossTargeting>$(_RestoreCrossTargeting)</CrossTargeting> + <RestoreLegacyPackagesDirectory>$(RestoreLegacyPackagesDirectory)</RestoreLegacyPackagesDirectory> + <ValidateRuntimeAssets>$(ValidateRuntimeIdentifierCompatibility)</ValidateRuntimeAssets> + <SkipContentFileWrite>$(_RestoreSkipContentFileWrite)</SkipContentFileWrite> + <ConfigFilePaths>$(_OutputConfigFilePaths)</ConfigFilePaths> + <TreatWarningsAsErrors>$(TreatWarningsAsErrors)</TreatWarningsAsErrors> + <WarningsAsErrors>$(WarningsAsErrors)</WarningsAsErrors> + <NoWarn>$(NoWarn)</NoWarn> + </_RestoreGraphEntry> + </ItemGroup> + + <!-- Use project.json --> + <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'ProjectJson' "> + <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())"> + <Type>ProjectSpec</Type> + <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName> + <ProjectPath>$(MSBuildProjectFullPath)</ProjectPath> + <ProjectName>$(_RestoreProjectName)</ProjectName> + <Sources>$(_OutputSources)</Sources> + <OutputPath>$(RestoreOutputAbsolutePath)</OutputPath> + <FallbackFolders>$(_OutputFallbackFolders)</FallbackFolders> + <PackagesPath>$(_OutputPackagesPath)</PackagesPath> + <ProjectJsonPath>$(_CurrentProjectJsonPath)</ProjectJsonPath> + <ProjectStyle>$(RestoreProjectStyle)</ProjectStyle> + <ConfigFilePaths>$(_OutputConfigFilePaths)</ConfigFilePaths> + </_RestoreGraphEntry> + </ItemGroup> + + <!-- Non-NuGet type --> + <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'Unknown' "> + <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())"> + <Type>ProjectSpec</Type> + <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName> + <ProjectPath>$(MSBuildProjectFullPath)</ProjectPath> + <ProjectName>$(_RestoreProjectName)</ProjectName> + <ProjectStyle>$(RestoreProjectStyle)</ProjectStyle> + <TargetFrameworks>@(_RestoreTargetFrameworksOutputFiltered)</TargetFrameworks> + </_RestoreGraphEntry> + </ItemGroup> + </Target> + + <!-- + ============================================================ + _GenerateRestoreDependencies + Generate items for package and project references. + ============================================================ + --> + <Target Name="_GenerateRestoreDependencies" + DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksAsItems" + Returns="@(_RestoreGraphEntry)"> + + <!-- Get project and package references --> + <!-- Evaluate for each framework --> + <MSBuild + Projects="$(MSBuildProjectFullPath)" + Targets="_GenerateProjectRestoreGraphPerFramework" + Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity); + %(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_RestoreGraphEntry" /> + </MSBuild> + </Target> + + <!-- + ============================================================ + _GenerateProjectRestoreGraph + Recursively walk project to project references. + ============================================================ + --> + <Target Name="_GenerateProjectRestoreGraph" + DependsOnTargets=" + _GetRestoreProjectStyle; + _GetRestoreTargetFrameworksOutput; + _GenerateRestoreProjectSpec; + _GenerateRestoreDependencies" + Returns="@(_RestoreGraphEntry)"> + + <!-- Output from dependency targets --> + </Target> + + <!-- + ============================================================ + _GenerateProjectRestoreGraphPerFramework + Walk dependencies using $(TargetFramework) + ============================================================ + --> + <Target Name="_GenerateProjectRestoreGraphPerFramework" + DependsOnTargets="_GetRestoreProjectStyle;CollectPackageReferences" + Returns="@(_RestoreGraphEntry)"> + + <!-- Write out project references --> + <GetRestoreProjectReferencesTask + ProjectUniqueName="$(MSBuildProjectFullPath)" + ProjectReferences="@(ProjectReference)" + TargetFrameworks="$(TargetFramework)" + ParentProjectPath="$(MSBuildProjectFullPath)"> + + <Output + TaskParameter="RestoreGraphItems" + ItemName="_RestoreGraphEntry" /> + </GetRestoreProjectReferencesTask> + + <!-- Write out package references for NETCore --> + <GetRestorePackageReferencesTask + Condition=" '$(RestoreProjectStyle)' == 'PackageReference' " + ProjectUniqueName="$(MSBuildProjectFullPath)" + PackageReferences="@(PackageReference)" + TargetFrameworks="$(TargetFramework)"> + + <Output + TaskParameter="RestoreGraphItems" + ItemName="_RestoreGraphEntry" /> + </GetRestorePackageReferencesTask> + + <PropertyGroup> + <_CombinedFallbacks>$(PackageTargetFallback);$(AssetTargetFallback)</_CombinedFallbacks> + </PropertyGroup> + + <!-- Write out target framework information --> + <ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(_CombinedFallbacks)' != '' "> + <_RestoreGraphEntry Include="$([System.Guid]::NewGuid())"> + <Type>TargetFrameworkInformation</Type> + <ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName> + <PackageTargetFallback>$(PackageTargetFallback)</PackageTargetFallback> + <AssetTargetFallback>$(AssetTargetFallback)</AssetTargetFallback> + <TargetFramework>$(TargetFramework)</TargetFramework> + </_RestoreGraphEntry> + </ItemGroup> + </Target> + + <!-- + ============================================================ + _GenerateRestoreProjectPathItemsPerFramework + Get absolute paths for all project references. + ============================================================ + --> + <Target Name="_GenerateRestoreProjectPathItemsPerFramework" + Returns="@(_RestoreProjectPathItems)"> + + <!-- Get the absolute paths to all projects --> + <ConvertToAbsolutePath Paths="@(ProjectReference)"> + <Output TaskParameter="AbsolutePaths" PropertyName="_RestoreGraphAbsoluteProjectPaths" /> + </ConvertToAbsolutePath> + + <ItemGroup> + <_RestoreProjectPathItems Include="$(_RestoreGraphAbsoluteProjectPaths)" /> + </ItemGroup> + </Target> + + <!-- + ============================================================ + _GenerateRestoreProjectPathItems + Get all project references regardless of framework + ============================================================ + --> + <Target Name="_GenerateRestoreProjectPathItems" + DependsOnTargets="_GetRestoreTargetFrameworksOutput;_GetRestoreTargetFrameworksAsItems" + Returns="@(_CurrentRestoreProjectPathItems)"> + + <!-- Get all project references for the current project --> + <MSBuild + Projects="$(MSBuildProjectFullPath)" + Targets="_GenerateRestoreProjectPathItemsPerFramework" + ContinueOnError="$(RestoreContinueOnError)" + Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity); + %(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_CurrentRestoreProjectPathItemsOutputs" /> + </MSBuild> + + <!-- Drop any duplicate items --> + <RemoveDuplicates + Inputs="@(_CurrentRestoreProjectPathItemsOutputs)"> + <Output + TaskParameter="Filtered" + ItemName="_CurrentRestoreProjectPathItems" /> + </RemoveDuplicates> + </Target> + + <!-- + ============================================================ + _GenerateRestoreProjectPathWalk + Recursively walk projects + ============================================================ + --> + <Target Name="_GenerateRestoreProjectPathWalk" + DependsOnTargets="_GenerateRestoreProjectPathItems;_GetRestoreTargetFrameworksAsItems" + Returns="@(_RestoreProjectPathItems)"> + + <!-- Walk project references --> + <MSBuild + Projects="@(_CurrentRestoreProjectPathItems)" + Targets="_GenerateRestoreProjectPathWalk" + ContinueOnError="$(RestoreContinueOnError)" + Properties="TargetFramework=%(_RestoreTargetFrameworkItems.Identity); + %(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_GenerateRestoreProjectPathWalkOutputs" /> + </MSBuild> + + <!-- Include the current project in the result --> + <ItemGroup> + <_GenerateRestoreProjectPathWalkOutputs Include="$(MSBuildProjectFullPath)" /> + </ItemGroup> + + <!-- Remove duplicates --> + <RemoveDuplicates + Inputs="@(_GenerateRestoreProjectPathWalkOutputs)"> + <Output + TaskParameter="Filtered" + ItemName="_RestoreProjectPathItems" /> + </RemoveDuplicates> + </Target> + + <!-- + ============================================================ + _GetAllRestoreProjectPathItems + Get the full list of known projects. + This includes all child projects from all target frameworks. + ============================================================ + --> + <Target Name="_GetAllRestoreProjectPathItems" + DependsOnTargets="_FilterRestoreGraphProjectInputItems" + Returns="@(_RestoreProjectPathItems)"> + + <!-- Walk projects --> + <MsBuild + Projects="@(FilteredRestoreGraphProjectInputItems)" + Targets="_GenerateRestoreProjectPathWalk" + ContinueOnError="$(RestoreContinueOnError)" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_RestoreProjectPathItemsOutputs" /> + </MsBuild> + + <!-- Remove duplicates --> + <RemoveDuplicates + Inputs="@(_RestoreProjectPathItemsOutputs)"> + <Output + TaskParameter="Filtered" + ItemName="_RestoreProjectPathItemsWithoutDupes" /> + </RemoveDuplicates> + + <!-- Remove projects that do not support restore. --> + <MsBuild + Projects="@(_RestoreProjectPathItemsWithoutDupes)" + Targets="_IsProjectRestoreSupported" + ContinueOnError="$(RestoreContinueOnError)" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform); + $(_GenerateRestoreGraphProjectEntryInputProperties)" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + ItemName="_RestoreProjectPathItems" /> + </MsBuild> + </Target> + + <!-- + ============================================================ + _GetRestoreSettingsOverrides + Get global property overrides that should be resolved + against the current working directory instead of the project. + This is done by calling into NuGet.targets in a new scope, + project properties will not be returned by the calls below. + ============================================================ + --> + <Target Name="_GetRestoreSettingsOverrides" + Returns="$(_RestorePackagesPathOverride);$(_RestoreSourcesOverride);$(_RestoreFallbackFoldersOverride)"> + + <!-- RestorePackagesPathOverride --> + <MsBuild + Condition=" '$(RestorePackagesPath)' != '' " + Projects="$(MSBuildThisFileFullPath)" + Targets="_GetRestorePackagesPathOverride" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform);" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + PropertyName="_RestorePackagesPathOverride" /> + </MsBuild> + + <!-- RestoreSourcesOverride --> + <MsBuild + Condition=" '$(RestoreSources)' != '' " + Projects="$(MSBuildThisFileFullPath)" + Targets="_GetRestoreSourcesOverride" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform);" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + PropertyName="_RestoreSourcesOverride" /> + </MsBuild> + + <!-- RestoreFallbackFoldersOverride --> + <MsBuild + Condition=" '$(RestoreFallbackFolders)' != '' " + Projects="$(MSBuildThisFileFullPath)" + Targets="_GetRestoreFallbackFoldersOverride" + Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); + %(_MSBuildProjectReferenceExistent.SetPlatform);" + RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"> + + <Output + TaskParameter="TargetOutputs" + PropertyName="_RestoreFallbackFoldersOverride" /> + </MsBuild> + </Target> + + <!-- + ============================================================ + _GetRestorePackagesPathOverride + ============================================================ + --> + <Target Name="_GetRestorePackagesPathOverride" + Returns="$(_RestorePackagesPathOverride)"> + <PropertyGroup> + <_RestorePackagesPathOverride>$(RestorePackagesPath)</_RestorePackagesPathOverride> + </PropertyGroup> + </Target> + + <!-- + ============================================================ + _GetRestoreSourcesOverride + ============================================================ + --> + <Target Name="_GetRestoreSourcesOverride" + Returns="$(_RestoreSourcesOverride)"> + <PropertyGroup> + <_RestoreSourcesOverride>$(RestoreSources)</_RestoreSourcesOverride> + </PropertyGroup> + </Target> + + <!-- + ============================================================ + _GetRestoreFallbackFoldersOverride + ============================================================ + --> + <Target Name="_GetRestoreFallbackFoldersOverride" + Returns="$(_RestoreFallbackFoldersOverride)"> + <PropertyGroup> + <_RestoreFallbackFoldersOverride>$(RestoreFallbackFolders)</_RestoreFallbackFoldersOverride> + </PropertyGroup> + </Target> + + <!-- + ============================================================ + _IsProjectRestoreSupported + Verify restore targets exist in the project. + ============================================================ + --> + <Target Name="_IsProjectRestoreSupported" + Returns="@(_ValidProjectsForRestore)"> + + <ItemGroup> + <_ValidProjectsForRestore Include="$(MSBuildProjectFullPath)" /> + </ItemGroup> + </Target> + +</Project> |