@@ -10,6 +10,7 @@ Copyright (c) .NET Foundation. All rights reserved.
10
10
***********************************************************************************************
11
11
-->
12
12
<Project xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
13
+ <UsingTask TaskName =" NuGetizer.Tasks.InferImplicitPackageReference" AssemblyFile =" NuGetizer.Tasks.dll" />
13
14
14
15
<PropertyGroup >
15
16
<!-- The Kind of primary output (build, symbols and doc) set if PackBuildOutput = true -->
@@ -36,6 +37,7 @@ Copyright (c) .NET Foundation. All rights reserved.
36
37
<GetPackageContentsDependsOn >
37
38
$(GetPackageContentsDependsOn);
38
39
_BuildOutputFrameworkSpecific;
40
+ _SetDefaultPackageReferencePack;
39
41
InferPackageContents
40
42
</GetPackageContentsDependsOn >
41
43
</PropertyGroup >
@@ -59,15 +61,24 @@ Copyright (c) .NET Foundation. All rights reserved.
59
61
</_ReferenceRelatedPaths >
60
62
</ItemDefinitionGroup >
61
63
62
- <Target Name =" _BuildOutputFrameworkSpecific" Returns =" $(BuildOutputFrameworkSpecific)" >
64
+ <Target Name =" _BuildOutputFrameworkSpecific" Condition = " '$(BuildOutputFrameworkSpecific)' == '' " Returns =" $(BuildOutputFrameworkSpecific)" >
63
65
<!-- Determine whether primary output is framework specific -->
64
- <ItemGroup Condition = " '$(BuildOutputFrameworkSpecific)' == '' " >
66
+ <ItemGroup >
65
67
<_BuildOutputKindFrameworkSpecific Include =" @(PackageItemKind->'%(FrameworkSpecific)')" Condition =" '%(Identity)' == '$(BuildOutputKind)'" />
66
68
</ItemGroup >
67
- <PropertyGroup Condition = " '$(BuildOutputFrameworkSpecific)' == '' " >
69
+ <PropertyGroup >
68
70
<BuildOutputFrameworkSpecific >@(_BuildOutputKindFrameworkSpecific)</BuildOutputFrameworkSpecific >
69
71
</PropertyGroup >
70
72
</Target >
73
+
74
+ <Target Name =" _SetDefaultPackageReferencePack" Condition =" '$(BuildOutputKind)' == 'build'"
75
+ BeforeTargets =" InferPrimaryOutputDependencies;InferPackageContents" >
76
+ <ItemGroup >
77
+ <PackageReference Update =" @(PackageReference)"
78
+ Condition =" $([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('Microsoft.Build')) and '%(Pack)' != 'true'"
79
+ Pack =" false" />
80
+ </ItemGroup >
81
+ </Target >
71
82
72
83
<Target Name =" InferPackageContents" DependsOnTargets =" $(InferPackageContentsDependsOn)" Returns =" @(PackageFile)" >
73
84
<!-- Ensure TargetPath -->
@@ -132,7 +143,7 @@ Copyright (c) .NET Foundation. All rights reserved.
132
143
Condition =" '%(_NoneToInfer.CopyToOutputDirectory)' == '' or '%(_NoneToInfer.CopyToOutputDirectory)' == 'Never'" >
133
144
<Kind Condition =" '%(_NoneToInfer.Kind)' == ''" >None</Kind >
134
145
</_InferredPackageFile >
135
-
146
+
136
147
<_InferredPackageFile Include =" @(PackageReference)"
137
148
Condition =" '%(PackageReference.Identity)' != 'NuGetizer' and
138
149
'%(PackageReference.Identity)' != 'NETStandard.Library' and
@@ -145,7 +156,9 @@ Copyright (c) .NET Foundation. All rights reserved.
145
156
it also includes mscorlib which we don't need
146
157
TBD: maybe include ResolvedFrom=ImplicitlyExpandDesignTimeFacades too? -->
147
158
<_InferredPackageFile Include =" @(ReferencePath->'%(OriginalItemSpec)')"
148
- Condition =" '$(PackFrameworkReferences)' == 'true' and '%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}' and '%(ReferencePath.Pack)' != 'false'" >
159
+ Condition =" '$(PackFrameworkReferences)' == 'true' and
160
+ '%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}' and
161
+ '%(ReferencePath.Pack)' != 'false'" >
149
162
<Kind >FrameworkReference</Kind >
150
163
</_InferredPackageFile >
151
164
</ItemGroup >
@@ -165,47 +178,60 @@ Copyright (c) .NET Foundation. All rights reserved.
165
178
</ItemGroup >
166
179
</Target >
167
180
168
- <Target Name =" _CollectPrimaryOutputRelatedFiles " DependsOnTargets =" BuildOnlySettings;ResolveReferences" Returns =" @(_PrimaryOutputRelatedFile )" >
181
+ <Target Name =" _CollectPrimaryOutputDependencies " DependsOnTargets =" BuildOnlySettings;ResolveReferences" Returns =" @(ImplicitPackageReference )" >
169
182
<ItemGroup >
170
183
<_PrimaryOutputRelatedFile Include =" @(ReferencePath);@(_ReferenceRelatedPaths)"
171
184
Condition =" '%(NuGetPackageId)' != 'NETStandard.Library' and
172
185
'%(Facade)' != 'true' and
173
186
'%(FrameworkFile)' != 'true' and
174
187
'%(Pack)' != 'false'" />
188
+ <_PrivateAssetsPackageReference Include =" @(PackageReference -> WithMetadataValue('PrivateAssets', 'all'))"
189
+ Condition =" '%(PackageReference.IsImplicitlyDefined)' != 'true' and '%(PackageReference.Pack)' != 'false'" />
175
190
</ItemGroup >
191
+ <InferImplicitPackageReference Condition =" '@(_PrivateAssetsPackageReference)' != '' and '@(PackageDependencies)' != ''"
192
+ PackageReferences =" @(_PrivateAssetsPackageReference)"
193
+ PackageDependencies =" @(PackageDependencies)" >
194
+ <Output TaskParameter =" ImplicitPackageReferences" ItemName =" ImplicitPackageReference" />
195
+ </InferImplicitPackageReference >
176
196
</Target >
197
+
198
+ <Target Name =" _ResolvePackageDependencies" Condition =" '$(UsingMicrosoftNETSdk)' == 'true'" DependsOnTargets =" RunResolvePackageDependencies" />
177
199
178
200
<Target Name =" InferPrimaryOutputDependencies"
179
201
Inputs =" @(_PrimaryOutputRelatedFile)"
180
202
Outputs =" %(_PrimaryOutputRelatedFile.NuGetPackageId)"
181
203
Returns =" @(_InferredPackageFile)"
182
- DependsOnTargets =" _CollectPrimaryOutputRelatedFiles" >
204
+ DependsOnTargets =" _ResolvePackageDependencies;_CollectPrimaryOutputDependencies" >
205
+
183
206
<ItemGroup >
184
207
<_NuGetPackageId Include =" @(_PrimaryOutputRelatedFile -> '%(NuGetPackageId)')" Condition =" '%(NuGetPackageId)' != 'NETStandard.Library'" />
185
208
</ItemGroup >
186
209
<PropertyGroup >
187
210
<_NuGetPackageId >@(_NuGetPackageId -> Distinct())</_NuGetPackageId >
188
211
</PropertyGroup >
189
212
<ItemGroup >
190
- <_PrimaryPackageReference Include =" @(PackageReference)" Condition =" '$(_NuGetPackageId)' != '' and '%(Identity)' == '$(_NuGetPackageId)'" />
213
+ <_PrimaryPackageReference Include =" @(PackageReference);@(ImplicitPackageReference) " Condition =" '$(_NuGetPackageId)' != '' and '%(Identity)' == '$(_NuGetPackageId)'" />
191
214
</ItemGroup >
215
+
192
216
<PropertyGroup >
193
217
<_PrivateAssets >@(_PrimaryPackageReference -> '%(PrivateAssets)')</_PrivateAssets >
218
+ <_ShouldPack >@(_PrimaryPackageReference -> '%(Pack)')</_ShouldPack >
194
219
<_ShouldIncludeAssetsRegex >$(_NuGetPackageId)\\.+\\$(_PrivateAssets)\\.*</_ShouldIncludeAssetsRegex >
195
220
</PropertyGroup >
196
221
197
- <ItemGroup Condition =" '$(_PrivateAssets)' == 'all'" >
222
+ <ItemGroup Condition =" '$(_ShouldPack)' != 'false' and '$( _PrivateAssets)' == 'all'" >
198
223
<_InferredPackageFile Include =" @(_PrimaryOutputRelatedFile)" Condition =" '%(_PrimaryOutputRelatedFile.FrameworkFile)' != 'true'" >
199
224
<Kind >$(BuildOutputKind)</Kind >
200
225
<FrameworkSpecific >$(BuildOutputFrameworkSpecific)</FrameworkSpecific >
201
226
</_InferredPackageFile >
202
227
</ItemGroup >
203
228
204
- <ItemGroup Condition =" '$(_PrivateAssets)' != 'all' and '$(_PrivateAssets)' != 'none' and '$(_PrivateAssets)' != ''" >
229
+ <ItemGroup Condition =" '$(_ShouldPack)' != 'false' and '$( _PrivateAssets)' != 'all' and '$(_PrivateAssets)' != 'none' and '$(_PrivateAssets)' != ''" >
205
230
<!-- In this case, we only add files that have a matching path to the private assets value.
206
231
i.e. for Mono.Options, PrivateAssets=lib, we'll include the file if its full path contains
207
232
'Mono.Options\*\lib\*', meaning the file is a lib. -->
208
- <_InferredPackageFile Include =" @(_PrimaryOutputRelatedFile)" Condition =" $([System.Text.RegularExpressions.Regex]::IsMatch('%(_PrimaryOutputRelatedFile.FullPath)', '$(_ShouldIncludeAssetsRegex)', 'RegexOptions.IgnoreCase')) == 'true'" >
233
+ <_InferredPackageFile Include =" @(_PrimaryOutputRelatedFile)"
234
+ Condition =" $([System.Text.RegularExpressions.Regex]::IsMatch('%(_PrimaryOutputRelatedFile.FullPath)', '$(_ShouldIncludeAssetsRegex)', 'RegexOptions.IgnoreCase')) == 'true'" >
209
235
<Kind >$(BuildOutputKind)</Kind >
210
236
<FrameworkSpecific >$(BuildOutputFrameworkSpecific)</FrameworkSpecific >
211
237
</_InferredPackageFile >
0 commit comments