This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathNuGet.Build.Packaging.targets
More file actions
403 lines (349 loc) · 21.3 KB
/
NuGet.Build.Packaging.targets
File metadata and controls
403 lines (349 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!--
***********************************************************************************************
Microsoft.NuGet.Build.Packaging.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.
***********************************************************************************************
-->
<Project InitialTargets="_SetPropertiesFromCapabilities" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="NuGet.Build.Packaging.Tasks.AssignPackagePath" AssemblyFile="NuGet.Build.Packaging.Tasks.dll" />
<UsingTask TaskName="NuGet.Build.Packaging.Tasks.CreatePackage" AssemblyFile="NuGet.Build.Packaging.Tasks.dll" />
<Import Project="NuGet.Build.Packaging.props" Condition="'$(NuGetBuildPackagingPropsImported)' == ''" />
<!-- Adds compatibility targets with Pack SDK -->
<Import Project="NuGet.Build.Packaging.Compatibility.props" />
<Import Project="NuGet.Build.Packaging.Legacy.props" />
<PropertyGroup>
<!-- Whether include referenced projects' contents the package -->
<IncludeProjectReferencesInPackage Condition="'$(IncludeProjectReferencesInPackage)' == ''">true</IncludeProjectReferencesInPackage>
<PackageRequireLicenseAcceptance Condition="'$(PackageRequireLicenseAcceptance)' == ''">false</PackageRequireLicenseAcceptance>
<!-- NOTE: we will always have this property in projects referencing this targets file. Can be used to detect this. -->
<IsPackable Condition="'$(IsPackable)' == '' and '$(PackageId)' != ''">true</IsPackable>
<IsPackable Condition="'$(IsPackable)' == '' and '$(PackageId)' == ''">false</IsPackable>
<!-- When the project is building a package, AssignPackagePath always assigns a PackagePath, regardless of the project PackageId -->
<BuildingPackage Condition="'$(BuildingPackage)' == '' and '$(IsPackagingProject)' == 'true'">true</BuildingPackage>
<!-- Directory where the .nupkg will be saved to if Pack is run, used also in GetPackageTargetPath -->
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(OutputPath)</PackageOutputPath>
<!-- This file signals that the Build should actually do a Pack. Supports the IDE solution-wide Build command for authoring projects. -->
<PackOnBuildFile>$(MSBuildProjectDirectory)\.packonbuild</PackOnBuildFile>
<!-- Whether to emit the nuspec that's used to create the final package -->
<EmitNuSpec Condition="'$(EmitNuSpec)' == ''">false</EmitNuSpec>
<!-- Only default the nuspec file if we are supposed to emit one. -->
<NuspecFile Condition="'$(NuspecFile)' == '' and '$(EmitNuSpec)' == 'true'">$(OutputPath)\$(PackageId).nuspec</NuspecFile>
</PropertyGroup>
<Import Project="NuGet.Build.Packaging.Inference.targets" Condition="'$(InferPackageContents)' != 'false'" />
<ItemGroup>
<!-- This is the capability that CPS in .NETStandard/.NETCore uses to enable the Pack context menu. Unify with that -->
<ProjectCapability Include="Pack" Condition="'$(IsPackable)' == 'true'" />
</ItemGroup>
<!-- Extends the built-in GetTargetPathWithTargetPlatformMoniker output to signal that the project has been nugetized -->
<ItemDefinitionGroup>
<TargetPathWithTargetPlatformMoniker>
<IsPackable>$(IsPackable)</IsPackable>
<IsNuGetized>true</IsNuGetized>
</TargetPathWithTargetPlatformMoniker>
</ItemDefinitionGroup>
<!--
=================================================================================================
GetPackageVersion
=================================================================================================
This target sets the default $(PackageVersion) to $(Version) if empty, and returns it.
The $(Version) property is the upcoming default way .NET projects are versioned. See
https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.GenerateAssemblyInfo.targets#L108
It can be redefined to change how the package version is
determined.
OUTPUTS:
$(PackageVersion) The determined package version
=================================================================================================
-->
<PropertyGroup>
<GetPackageVersionDependsOn>
$(GetPackageVersionDependsOn);
_SetDefaultPackageVersion
</GetPackageVersionDependsOn>
</PropertyGroup>
<Target Name="GetPackageVersion" DependsOnTargets="$(GetPackageVersionDependsOn)" Returns="$(PackageVersion)" />
<Target Name="_SetDefaultPackageVersion" Condition="'$(PackageVersion)' == ''" Returns="$(PackageVersion)">
<PropertyGroup>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">$(Version)</PackageVersion>
</PropertyGroup>
</Target>
<!--
=================================================================================================
GetPackageTargetPath
=================================================================================================
If the project builds a package (that is, it has a PackageId),
this target returns an item for the $(PackageTargetPath) that
the project builds, as well as manifest metadata included in
the project for the resulting package, not including its
contents and dependencies, which must be retrieved from the
GetPackageContents target instead.
OUTPUTS:
@(PackageTargetPath) The metadata of the package that would be built.
=================================================================================================
-->
<PropertyGroup>
<GetPackageTargetPathDependsOn>
$(GetPackageTargetPathDependsOn);
GetPackageVersion;
_SetDefaultPackageTargetPath;
</GetPackageTargetPathDependsOn>
</PropertyGroup>
<Target Name="GetPackageTargetPath" Condition="'$(IsPackable)' == 'true'" DependsOnTargets="$(GetPackageTargetPathDependsOn)" Returns="@(PackageTargetPath)">
<Error Text="The 'PackageVersion' property cannot be empty." Code="NG1002" Condition="'$(PackageVersion)' == ''" />
<ItemGroup>
<!-- Ensure we got a full path -->
<PackageTargetPath Include="$([System.IO.Path]::GetFullPath('$(PackageTargetPath)'))">
<Id>$(PackageId)</Id>
<Version>$(PackageVersion)</Version>
<DevelopmentDependency Condition="'$(IsDevelopmentDependency)' == 'true'">true</DevelopmentDependency>
<Authors>$(Authors)</Authors>
<Owners>$(Owners)</Owners>
<Title>$(Title)</Title>
<Description>$(Description)</Description>
<Summary>$(Summary)</Summary>
<Language>$(NeutralLanguage)</Language>
<Copyright>$(Copyright)</Copyright>
<RequireLicenseAcceptance>$(PackageRequireLicenseAcceptance)</RequireLicenseAcceptance>
<LicenseUrl>$(PackageLicenseUrl)</LicenseUrl>
<ProjectUrl>$(PackageProjectUrl)</ProjectUrl>
<IconUrl>$(PackageIconUrl)</IconUrl>
<Tags>$(PackageTags)</Tags>
<ReleaseNotes>$(PackageReleaseNotes)</ReleaseNotes>
<RepositoryUrl>$(RepositoryUrl)</RepositoryUrl>
<RepositoryType>$(RepositoryType)</RepositoryType>
<PackageTypes>$(PackageTypes)</PackageTypes>
</PackageTargetPath>
</ItemGroup>
</Target>
<Target Name="_SetDefaultPackageTargetPath" Condition="'$(IsPackable)' == 'true' and '$(PackageTargetPath)' == '' and '$(PackageVersion)' != ''">
<PropertyGroup>
<PackageTargetPath Condition="'$(PackageTargetPath)' == ''">$([System.IO.Path]::Combine('$(PackageOutputPath)', '$(PackageId).$(PackageVersion).nupkg'))</PackageTargetPath>
</PropertyGroup>
</Target>
<!--
=================================================================================================
PackageOutputGroup
=================================================================================================
For compatibility and naming consistency with the targets in AllProjectOutputGroups, this target
returns the same output as GetPackageTargetPath
OUTPUTS:
@(PackageTargetPath) The metadata of the package that would be built.
=================================================================================================
-->
<PropertyGroup>
<PackageOutputGroupDependsOn>GetPackageTargetPath;$(PackageOutputGroupDependsOn)</PackageOutputGroupDependsOn>
</PropertyGroup>
<Target Name="PackageOutputGroup" BeforeTargets="AllProjectOutputGroups" Returns="@(PackageTargetPath)" DependsOnTargets="$(PackageOutputGroupDependsOn)" />
<!--
=================================================================================================
GetPackageContents
=================================================================================================
Returns the "virtual package" for the current project, containing
all items that would end up in a .nupkg if the project were
to be packed.
If the project has NuGet metadata to generate a .nupkg, a metadata
item containing the manifest information will also be returned, as
Identity=$(PackageId)
%(Kind)=Metadata
... all manifest values as metadata items ...
All items returned from this target contain a %(PackageId) metadata
with the project's $(PackageId), if any.
OUTPUTS:
@(_PackageContent) The contents that this project contributes to a package
=================================================================================================
-->
<PropertyGroup>
<GetPackageContentsDependsOn>
$(GetPackageContentsDependsOn);
GetPackageTargetPath;
_AddPackageManifest
</GetPackageContentsDependsOn>
<GetPackageContentsDependsOn Condition="'$(IncludeProjectReferencesInPackage)' == 'true'">
$(GetPackageContentsDependsOn);
_GetReferencedPackageContents
</GetPackageContentsDependsOn>
</PropertyGroup>
<Target Name="GetPackageContents" DependsOnTargets="$(GetPackageContentsDependsOn)" Returns="@(_PackageContent)">
<ItemGroup>
<!--
PackageId metadata on all PackageFile items means we can tell appart which ones came from which dependencies
NOTE: if PackageId is empty, we won't generate a manifest and it means the files need to be packed with the
current project.
-->
<PackageFile>
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
<Platform Condition="'%(PackageFile.Platform)' == ''">$(Platform)</Platform>
<TargetFrameworkMoniker Condition="'%(PackageFile.TargetFrameworkMoniker)' == '' and '$(IsPackagingProject)' != 'true'">$(TargetFrameworkMoniker)</TargetFrameworkMoniker>
</PackageFile>
</ItemGroup>
<!-- We batch depending on the IsPackaging metadata, which is only specified for referenced content
if the current project is building a package, to force retargeting of the referenced content. -->
<AssignPackagePath Files="@(PackageFile)" Kinds="@(PackageItemKind)" IsPackaging="%(PackageFile.IsPackaging)">
<Output TaskParameter="AssignedFiles" ItemName="_PackageContent" />
</AssignPackagePath>
</Target>
<Target Name="_AddPackageManifest" Condition="'$(IsPackable)' == 'true'">
<!-- If packaging the project, provide the metadata as a non-file item -->
<ItemGroup>
<PackageFile Include="@(PackageTargetPath->'%(Id)')" Condition="'$(IsPackable)' == 'true'">
<Kind>Metadata</Kind>
<PackageId>$(PackageId)</PackageId>
<Platform>$(Platform)</Platform>
<TargetFrameworkMoniker Condition="'$(IsPackagingProject)' != 'true'">$(TargetFrameworkMoniker)</TargetFrameworkMoniker>
</PackageFile>
</ItemGroup>
</Target>
<Target Name="_GetReferencedPackageContents"
Condition="'$(_SupportsProjectReferences)' == 'true'"
DependsOnTargets="$(_GetReferencedPackageContentsDependsOn)"
Returns="@(PackageFile)">
<Error Condition="'@(_NonNuGetizedProjectReference)' != ''"
Code="NG0011"
Text="Some project references cannot be properly packaged. Please install the NuGet.Build.Packaging package on the following projects: @(_NonNuGetizedProjectReference)." />
<!--
PackageId metadata on all PackageFile items means we can tell appart which ones came from which dependencies
NOTE: if PackageId is empty, we won't generate a manifest and it means the files need to be packed with the
current project.
-->
<MSBuild Projects="@(_NuGetizedProjectReference)"
Targets="GetPackageContents"
BuildInParallel="$(BuildInParallel)"
Properties="%(_NuGetizedProjectReference.SetConfiguration); %(_NuGetizedProjectReference.SetPlatform); BuildingPackage=$(BuildingPackage)"
Condition="'@(ProjectReferenceWithConfiguration)' != '' and '@(_NuGetizedProjectReference)' != ''"
RemoveProperties="%(_NuGetizedProjectReference.GlobalPropertiesToRemove)">
<Output TaskParameter="TargetOutputs" ItemName="_ReferencedPackageContent" />
</MSBuild>
<ItemGroup>
<_ReferencedPackageDependency Include="@(_ReferencedPackageContent)"
Condition="'%(_ReferencedPackageContent.PackageId)' != '$(PackageId)' and '%(_ReferencedPackageContent.Kind)' == 'Metadata'">
<!-- For consistency, annotate like the rest -->
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
<TargetFrameworkMoniker Condition="'$(IsPackagingProject)' != 'true'">$(TargetFrameworkMoniker)</TargetFrameworkMoniker>
<Kind>Dependency</Kind>
</_ReferencedPackageDependency>
<!-- Remove the referenced package actual contents if it provides a manifest, since it will be a dependency in that case. -->
<_PackageContentFromDependency Include="@(_ReferencedPackageContent)"
Condition="'%(_ReferencedPackageContent.PackageId)' != '' and
'%(_ReferencedPackageContent.PackageId)' != '$(PackageId)'" />
<_ReferencedPackageContent Remove="@(_PackageContentFromDependency)" />
</ItemGroup>
<!-- Always annotate package contents with the original target framework and moniker -->
<CreateItem Include="@(_ReferencedPackageContent)" PreserveExistingMetadata="true"
Condition="'@(_ReferencedPackageContent)' != ''"
AdditionalMetadata="OriginalTargetFramework=%(_ReferencedPackageContent.TargetFramework);OriginalTargetFrameworkMoniker=%(_ReferencedPackageContent.TargetFrameworkMoniker)">
<Output TaskParameter="Include" ItemName="_ReferencedPackageContentWithOriginalValues"/>
</CreateItem>
<ItemGroup Condition="'$(IsPackagingProject)' != 'true'">
<!-- Retarget content for the currently building package, if necessary -->
<_ReferencedPackageContentWithOriginalValues Condition="'%(_ReferencedPackageContentWithOriginalValues.PackageId)' == ''">
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
<!-- Clear the target framework since it trumps the TFM in AsignPackagePath now -->
<!-- Only do this for assets that come from project references that don't build nugets themselves (IsPackagingProject=='true' above) -->
<TargetFramework></TargetFramework>
<!-- NOTE: we're always overwriting the TFM for framework-specific
items in this case since this item will end up making up the
contents of this package project in its current TFM configuration.
TBD: we might want to preserve it anyways and adjust later
(i.e. net45 project references netstandard1.6 project)
TODO: take into account cross-targeting.
-->
<TargetFrameworkMoniker Condition="'%(_ReferencedPackageContentWithOriginalValues.FrameworkSpecific)' == 'true'">$(TargetFrameworkMoniker)</TargetFrameworkMoniker>
</_ReferencedPackageContentWithOriginalValues>
</ItemGroup>
<!-- Otherwise, assign target paths based on the original TFM -->
<ItemGroup Condition="'$(IsPackagingProject)' == 'true'">
<!-- Retarget content for the currently building package, if necessary -->
<_ReferencedPackageContentWithOriginalValues Condition="'%(_ReferencedPackageContentWithOriginalValues.PackageId)' == ''">
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
<!-- Clear the target framework since it trumps the TFM in AsignPackagePath now -->
<!-- Only do this for framework-specifc assets that come from project references that don't build nugets (PackageId=='' above) -->
<TargetFramework Condition="'%(_ReferencedPackageContentWithOriginalValues.FrameworkSpecific)' == 'true'"></TargetFramework>
<TargetFrameworkMoniker>%(_ReferencedPackageContentWithOriginalValues.OriginalTargetFrameworkMoniker)</TargetFrameworkMoniker>
</_ReferencedPackageContentWithOriginalValues>
</ItemGroup>
<ItemGroup>
<!-- Ensure referenced package content gets assigned a package path if it didn't provide one already.
This happens for project references' that don't have a PackageId, since their package path will
depend on the referencing project's TFM.
-->
<PackageFile Include="@(_ReferencedPackageContentWithOriginalValues);@(_ReferencedPackageDependency)">
<IsPackaging>$(BuildingPackage)</IsPackaging>
</PackageFile>
</ItemGroup>
</Target>
<!-- This target separates project references that have the packaging targets from those that don't -->
<Target Name="_SplitProjectReferencesByIsNuGetized"
Condition="'@(ProjectReferenceWithConfiguration)' != '' and '@(_MSBuildProjectReferenceExistent)' != ''"
Inputs="@(_MSBuildProjectReferenceExistent)"
Outputs="%(_MSBuildProjectReferenceExistent.Identity)-BATCH">
<MSBuild Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetTargetPathWithTargetPlatformMoniker"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
<Output TaskParameter="TargetOutputs" ItemName="_ReferencedProjectTargetPath" />
</MSBuild>
<PropertyGroup>
<_IsNuGetized Condition="'%(_ReferencedProjectTargetPath.IsNuGetized)' != ''">true</_IsNuGetized>
</PropertyGroup>
<ItemGroup>
<!-- We will fail for this first group: project references that aren't excluded from packaging, yet haven't been nugetized -->
<_NonNuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)" Condition="'%(_MSBuildProjectReferenceExistent.Pack)' != 'false' and '$(_IsNuGetized)' != 'true'" />
<!-- We will only process for packaging the project references that haven't been excluded from packaging and are nugetized -->
<_NuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)" Condition="'%(_MSBuildProjectReferenceExistent.Pack)' != 'false' and '$(_IsNuGetized)' == 'true'" />
</ItemGroup>
</Target>
<PropertyGroup>
<!-- If we're packing on build, just add Pack as a dependency for Build -->
<_ShouldPackOnBuild Condition="('$(PackOnBuild)' == 'true' Or Exists('$(PackOnBuildFile)')) And '$(IsPackable)' == 'true'">true</_ShouldPackOnBuild>
<BuildDependsOn Condition="'$(_ShouldPackOnBuild)' == 'true'">
$(BuildDependsOn);
Pack;
</BuildDependsOn>
<!-- If we're not packing on build, set up a dependency from Pack>Build for non-NuProj that are packable, so Build runs before Pack -->
<PackDependsOn Condition="'$(IsPackagingProject)' != 'true' And '$(_ShouldPackOnBuild)' != 'true' And '$(IsPackable)' == 'true'">
Build;
</PackDependsOn>
<PackDependsOn>
$(PackDependsOn)
GetPackageTargetPath;
GetPackageContents
</PackDependsOn>
</PropertyGroup>
<!--
=================================================================================================
Pack
=================================================================================================
Creates the output .nupkg if the project is packable.
OUTPUTS:
@(PackageTargetPath) The output path of the package that was built with its metadata.
=================================================================================================
-->
<Target Name="Pack" DependsOnTargets="$(PackDependsOn)" Returns="@(PackageTargetPath)" Condition="'$(IsPackable)' == 'true'">
<MakeDir Directories="$(PackageOutputPath)" Condition="!Exists('$(PackageOutputPath)')" />
<CreatePackage Manifest="@(PackageTargetPath)" NuspecFile="$(NuspecFile)" BaseNuspecFile="$(BaseNuspecFile)" Contents="@(_PackageContent)" TargetPath="@(PackageTargetPath->'%(FullPath)')">
<Output TaskParameter="OutputPackage" ItemName="_PackageTargetPath" />
<Output TaskParameter="OutputPackage" ItemName="FileWrites" />
</CreatePackage>
<Message Importance="high" Text="Created package at %(_PackageTargetPath.FullPath)." />
</Target>
<Target Name="_SetPropertiesFromCapabilities">
<PropertyGroup>
<_AllProjectCapabilities>@(ProjectCapability)</_AllProjectCapabilities>
<!-- NOTE: this avoids taking dependencies on targets that are only available when the project supports the concept of project references -->
<_SupportsProjectReferences>$(_AllProjectCapabilities.Contains('ProjectReferences'))</_SupportsProjectReferences>
<_GetReferencedPackageContentsDependsOn Condition="'$(_SupportsProjectReferences)' == 'true'">
$(_GetReferencedPackageContentsDependsOn);
AssignProjectConfiguration;
_SplitProjectReferencesByFileExistence;
_SplitProjectReferencesByIsNuGetized
</_GetReferencedPackageContentsDependsOn>
</PropertyGroup>
</Target>
<Import Project="NuGet.Build.Packaging.ReferenceAssembly.targets" />
<Import Project="NuGet.Build.Packaging.Authoring.targets" Condition="'$(IsPackagingProject)' == 'true'" />
<Import Project="NuGet.Build.Packaging.CrossTargeting.targets" Condition="'$(IsCrossTargetingBuild)' == 'true' And '$(FromPackagingProject)' == 'true'" />
<Import Project="NuGet.Build.Packaging.Legacy.targets" />
</Project>