1+ <!--
2+ ***********************************************************************************************
3+ Microsoft.NuGet.Build.Packaging.Inference.targets
4+
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.
8+
9+ Copyright (c) .NET Foundation. All rights reserved.
10+ ***********************************************************************************************
11+ -->
12+ <Project xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
13+ <UsingTask TaskName =" NuGet.Build.Packaging.Tasks.ReadLegacyJsonDependencies" AssemblyFile =" NuGet.Build.Packaging.Tasks.dll" />
14+ <UsingTask TaskName =" NuGet.Build.Packaging.Tasks.ReadLegacyConfigDependencies" AssemblyFile =" NuGet.Build.Packaging.Tasks.dll" />
15+
16+ <PropertyGroup >
17+ <!-- Infer PackageReference elements from packages.config/project.json files in the project -->
18+ <InferLegacyPackageReferences Condition =" '$(InferLegacyPackageReferences)' == ''" >true</InferLegacyPackageReferences >
19+
20+ <!-- The Kind of primary output (build, symbols and doc) set if IncludeOutputsInPackage = true -->
21+ <PrimaryOutputKind Condition =" '$(PrimaryOutputKind)' == ''" >Lib</PrimaryOutputKind >
22+ <!-- Optionally can tweak whether the primary output is TF-specific or not. -->
23+ <PrimaryOutputFrameworkSpecific Condition =" '$(PrimaryOutputKind)' == ''" >true</PrimaryOutputFrameworkSpecific >
24+
25+ <!-- Whether to include @(Content) items with CopyToOutputDirectory != '' in the package -->
26+ <IncludeContentInPackage Condition =" '$(IncludeContentInPackage)' == ''" >true</IncludeContentInPackage >
27+ <!-- Whether to include @(None) items with CopyToOutputDirectory != '' in the package -->
28+ <IncludeNoneInPackage Condition =" '$(IncludeNoneInPackage)' == ''" >true</IncludeNoneInPackage >
29+ <!-- Whether to include @(BuiltProjectOutputGroupOutput), @(DocumentationProjectOutputGroupOutput) and @(SatelliteDllsProjectOutputGroupOutput) items in the package -->
30+ <IncludeOutputsInPackage Condition =" '$(IncludeOutputsInPackage)' == ''" >true</IncludeOutputsInPackage >
31+ <!-- Whether to include @(DebugSymbolsProjectOutputGroupOutput) items in the package -->
32+ <IncludeSymbolsInPackage Condition =" '$(IncludeSymbolsInPackage)' == '' and '$(IncludeOutputsInPackage)' == 'true' and '$(Configuration)' == 'Debug'" >true</IncludeSymbolsInPackage >
33+ <!-- Whether to include framework references (%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}') in the package -->
34+
35+ <!-- Only default to true if the project isn't a nuget packaging project itself and its primary output is lib. -->
36+ <IncludeFrameworkReferencesInPackage Condition =" '$(IncludeFrameworkReferencesInPackage)' == '' and '$(IsPackagingProject)' != 'true' and '$(PrimaryOutputKind)' == 'Lib'" >true</IncludeFrameworkReferencesInPackage >
37+ </PropertyGroup >
38+
39+ <PropertyGroup >
40+ <GetPackageContentsDependsOn >
41+ $(GetPackageContentsDependsOn);
42+ InferPackageContents
43+ </GetPackageContentsDependsOn >
44+ </PropertyGroup >
45+
46+ <Target Name =" InferPackageContents" DependsOnTargets =" $(InferPackageContentsDependsOn)" Returns =" @(PackageFile)" >
47+ <!-- Determine whether primary output is framework specific -->
48+ <ItemGroup Condition =" '$(PrimaryOutputFrameworkSpecific)' == ''" >
49+ <_PrimaryOutputKind Include =" @(PackageItemKind->'%(FrameworkSpecific)')" Condition =" '%(Identity)' == '$(PrimaryOutputKind)'" />
50+ </ItemGroup >
51+ <PropertyGroup Condition =" '$(PrimaryOutputFrameworkSpecific)' == ''" >
52+ <PrimaryOutputFrameworkSpecific >@(_PrimaryOutputKind)</PrimaryOutputFrameworkSpecific >
53+ </PropertyGroup >
54+
55+ <ItemGroup >
56+ <_InferredPackageFile Include =" @(BuiltProjectOutputGroupOutput -> '%(FinalOutputPath)')"
57+ Condition =" '$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'" >
58+ <!-- Packaging projects don't contribute primary output -->
59+ <Kind >$(PrimaryOutputKind)</Kind >
60+ <FrameworkSpecific >$(PrimaryOutputFrameworkSpecific)</FrameworkSpecific >
61+ </_InferredPackageFile >
62+
63+ <!-- Remove when https://github.com/Microsoft/msbuild/pull/1076 ships -->
64+ <_DocumentationProjectOutputGroupOutput Include =" @(DocumentationProjectOutputGroupOutput)"
65+ Condition =" '$(IncludeOutputsInPackage)' == 'true'" >
66+ <FinalOutputPath Condition =" $([System.IO.Path]::IsPathRooted('%(FinalOutputPath)')) == 'false'" >$(MSBuildProjectDirectory)\%(FinalOutputPath)</FinalOutputPath >
67+ </_DocumentationProjectOutputGroupOutput >
68+ <_InferredPackageFile Include =" @(_DocumentationProjectOutputGroupOutput -> '%(FinalOutputPath)')"
69+ Condition =" '$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'" >
70+ <!-- Packaging projects don't contribute primary docs -->
71+ <Kind >$(PrimaryOutputKind)</Kind >
72+ <FrameworkSpecific >$(PrimaryOutputFrameworkSpecific)</FrameworkSpecific >
73+ </_InferredPackageFile >
74+
75+ <_InferredPackageFile Include =" @(DebugSymbolsProjectOutputGroupOutput -> '%(FinalOutputPath)')"
76+ Condition =" '$(IncludeOutputsInPackage)' == 'true' and '$(IncludeSymbolsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'" >
77+ <!-- Packaging projects don't contribute primary symbols -->
78+ <Kind >$(PrimaryOutputKind)</Kind >
79+ <FrameworkSpecific >$(PrimaryOutputFrameworkSpecific)</FrameworkSpecific >
80+ </_InferredPackageFile >
81+
82+ <!-- Change to %(FinalOutputPath) when https://github.com/Microsoft/msbuild/pull/1115 ships -->
83+ <_InferredPackageFile Include =" @(SatelliteDllsProjectOutputGroupOutput -> '%(FullPath)')"
84+ Condition =" '$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'" >
85+ <!-- Packaging projects don't contribute satellite dlls -->
86+ <Kind >$(PrimaryOutputKind)</Kind >
87+ <FrameworkSpecific >$(PrimaryOutputFrameworkSpecific)</FrameworkSpecific >
88+ </_InferredPackageFile >
89+
90+ <!-- NOTE: Content is opt-out (must have IncludeInPackage=false to exclude if IncludeContentInPackage=true) -->
91+ <!-- @ContentFilesProjectOutputGroupOutput = @(ContentWithTargetPath -> '%(FullPath)') -->
92+ <_InferredPackageFile Include =" @(ContentWithTargetPath->'%(FullPath)')"
93+ Condition ="
94+ '%(ContentWithTargetPath.IncludeInPackage)' == 'true' or
95+ '%(ContentWithTargetPath.Kind)' != '' or
96+ ('$(IncludeContentInPackage)' == 'true' and '%(ContentWithTargetPath.IncludeInPackage)' != 'false')" >
97+ <Kind Condition =" '%(ContentWithTargetPath.Kind)' == '' and '%(ContentWithTargetPath.CopyToOutputDirectory)' != ''" >$(PrimaryOutputKind)</Kind >
98+ <Kind Condition =" '%(ContentWithTargetPath.Kind)' == '' and '%(ContentWithTargetPath.CopyToOutputDirectory)' == ''" >Content</Kind >
99+ </_InferredPackageFile >
100+
101+ <!-- NOTE: None is also opt-out (must have IncludeInPackage=false to exclude if IncludeNoneInPackage=true, but only for those with CopyToOutput) -->
102+ <_InferredPackageFile Include =" @(_NoneWithTargetPath->'%(FullPath)')"
103+ Condition ="
104+ '%(_NoneWithTargetPath.IncludeInPackage)' == 'true' or
105+ '%(_NoneWithTargetPath.Kind)' != '' or
106+ ('$(IncludeNoneInPackage)' == 'true' and '%(_NoneWithTargetPath.CopyToOutputDirectory)' != '' and '%(_NoneWithTargetPath.IncludeInPackage)' != 'false')" >
107+ <Kind Condition =" '%(_NoneWithTargetPath.Kind)' == '' and '%(_NoneWithTargetPath.CopyToOutputDirectory)' != ''" >$(PrimaryOutputKind)</Kind >
108+ </_InferredPackageFile >
109+
110+ <_InferredPackageFile Include =" @(PackageReference)" Condition =" '%(Identity)' != 'NuGet.Build.Packaging'" >
111+ <Kind >Dependency</Kind >
112+ </_InferredPackageFile >
113+
114+ <!-- We can't use %(FrameworkFile)==true because it's not defined for raw file references and
115+ it also includes mscorlib which we don't need
116+ TBD: maybe include ResolvedFrom=ImplicitlyExpandDesignTimeFacades too? -->
117+ <_InferredPackageFile Include =" @(ReferencePath->'%(OriginalItemSpec)')"
118+ Condition =" '$(IncludeFrameworkReferencesInPackage)' == 'true' and '%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}'" >
119+ <Kind >FrameworkReference</Kind >
120+ </_InferredPackageFile >
121+ </ItemGroup >
122+
123+ <ItemGroup >
124+ <!--
125+ PackageId metadata on all PackageFile items means we can tell appart which ones came from which dependencies
126+ NOTE: if PackageId is empty, we won't generate a manifest and it means the files need to be packed with the
127+ current project.
128+ -->
129+ <PackageFile Include =" @(_InferredPackageFile)" >
130+ <Source >Implicit</Source >
131+ <PackageId Condition =" '$(IsPackable)' == 'true'" >$(PackageId)</PackageId >
132+ <Platform >$(Platform)</Platform >
133+ <TargetFrameworkMoniker Condition =" '$(IsPackagingProject)' != 'true'" >$(TargetFrameworkMoniker)</TargetFrameworkMoniker >
134+ </PackageFile >
135+ </ItemGroup >
136+ </Target >
137+
138+ <Target Name =" _SetInferPackageContentsDependsOn" AfterTargets =" _SetPropertiesFromCapabilities" >
139+ <PropertyGroup >
140+ <!-- NOTE: this avoids taking dependencies on targets that are only available when the project supports the concept of references -->
141+ <_SupportsReferences Condition ="
142+ $(_AllProjectCapabilities.Contains('AssemblyReferences')) or
143+ $(_AllProjectCapabilities.Contains('COMReferences')) or
144+ $(_AllProjectCapabilities.Contains('ProjectReferences')) or
145+ $(_AllProjectCapabilities.Contains('WinRTReferences')) or
146+ $(_AllProjectCapabilities.Contains('SDKReferences'))" >true</_SupportsReferences >
147+
148+ <!-- Only depend on ResolveReferences if we need to include framework references -->
149+ <InferPackageContentsDependsOn Condition =" '$(IncludeFrameworkReferencesInPackage)' == 'true' and '$(_SupportsReferences)' == 'true'" >
150+ ResolveReferences
151+ </InferPackageContentsDependsOn >
152+ <InferPackageContentsDependsOn >
153+ $(InferPackageContentsDependsOn);
154+ GetPackageTargetPath
155+ </InferPackageContentsDependsOn >
156+ <InferPackageContentsDependsOn Condition =" $(_AllProjectCapabilities.Contains('AllTargetOutputGroups'))" >
157+ $(InferPackageContentsDependsOn);
158+ AllProjectOutputGroups
159+ </InferPackageContentsDependsOn >
160+ </PropertyGroup >
161+ </Target >
162+
163+ <Target Name =" ReadLegacyDependencies" BeforeTargets =" InferPackageContents" Condition =" '$(InferLegacyPackageReferences)' == 'true'" >
164+ <PropertyGroup >
165+ <_ProjectJson >$(MSBuildProjectDirectory)\project.json</_ProjectJson >
166+ <_PackagesConfig >$(MSBuildProjectDirectory)\packages.config</_PackagesConfig >
167+ </PropertyGroup >
168+
169+ <ReadLegacyJsonDependencies ProjectJsonPath =" $(_ProjectJson)" Condition =" Exists('$(_ProjectJson)')" >
170+ <Output TaskParameter =" PackageReferences" ItemName =" PackageReference" />
171+ </ReadLegacyJsonDependencies >
172+
173+ <ReadLegacyConfigDependencies PackagesConfigPath =" $(_PackagesConfig)" Condition =" Exists('$(_PackagesConfig)')" >
174+ <Output TaskParameter =" PackageReferences" ItemName =" PackageReference" />
175+ </ReadLegacyConfigDependencies >
176+ </Target >
177+
178+ </Project >
0 commit comments