@@ -93,7 +93,7 @@ Copyright (c) .NET Foundation. All rights reserved.
93
93
<UsingTask TaskName =" CheckForImplicitPackageReferenceOverrides" AssemblyFile =" $(MicrosoftNETBuildTasksAssembly)" />
94
94
95
95
<!-- Remove package references with metadata IsImplicitlyDefined = true, if there are other PackageReference items with the same identity -->
96
- <Target Name =" CheckForImplicitPackageReferenceOverrides" BeforeTargets =" _GetRestoreProjectStyle; _CheckForInvalidConfigurationAndPlatform;CollectPackageReferences" >
96
+ <Target Name =" CheckForImplicitPackageReferenceOverrides" BeforeTargets =" _CheckForInvalidConfigurationAndPlatform;CollectPackageReferences" >
97
97
<PropertyGroup >
98
98
<ImplicitPackageReferenceInformationLink >https://aka.ms/sdkimplicitrefs</ImplicitPackageReferenceInformationLink >
99
99
</PropertyGroup >
@@ -112,6 +112,41 @@ Copyright (c) .NET Foundation. All rights reserved.
112
112
113
113
</Target >
114
114
115
+ <!-- Running an SDK task before the NuGet restore task causes issues when running on .NET Framework because it causes the
116
+ .NET Standard NuGet DLLs to be loaded from the SDK path rather than the .NET Framework versions from the NuGet targets
117
+ path. To avoid this, we create a separate target to run before NuGet restore which deduplicates the items without
118
+ causing the SDK tasks to be loaded (but doesn't generate a warning message, because we need to load the tasks for that). -->
119
+ <PropertyGroup Condition =" '$(DisableImplicitFrameworkReferences)' != 'true'" >
120
+ <_ImplicitPackageName Condition =" '$(TargetFrameworkIdentifier)' == '.NETStandard'" >NETStandard.Library</_ImplicitPackageName >
121
+ <_ImplicitPackageName Condition =" '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" >Microsoft.NETCore.App</_ImplicitPackageName >
122
+ </PropertyGroup >
123
+
124
+ <ItemGroup Condition =" '$(_ImplicitPackageName)' != ''" >
125
+ <!-- Filter PackageReference to items where the ItemSpec matches the implicit package name, and add IsImplicitlyDefined metadata
126
+ for items that don't have it-->
127
+ <_ImplicitPackageReferenceCheck
128
+ Include =" @(PackageReference->WithMetadataValue('Identity', '$(_ImplicitPackageName)'))" >
129
+ <IsImplicitlyDefined Condition =" '%(IsImplicitlyDefined)' != 'true' " >false</IsImplicitlyDefined >
130
+ </_ImplicitPackageReferenceCheck >
131
+
132
+ <!-- Now filter down to an item with just the implicit reference and another one with just the overriding reference -->
133
+ <_ImplicitPackageReference Include =" @(_ImplicitPackageReferenceCheck->WithMetadataValue('IsImplicitlyDefined', 'true'))" />
134
+ <_OverridingPackageReference Include =" @(_ImplicitPackageReferenceCheck->WithMetadataValue('IsImplicitlyDefined', 'false'))" />
135
+ </ItemGroup >
136
+
137
+ <Target Name =" CheckForImplicitPackageReferenceOverridesBeforeRestore" BeforeTargets =" _GetRestoreProjectStyle" >
138
+ <ItemGroup >
139
+ <!-- Remove both the implicit and the override item, if there was both an implicit and an override item -->
140
+ <PackageReference Remove =" @(PackageReference->WithMetadataValue('Identity', '$(_ImplicitPackageName)'))"
141
+ Condition =" '@(_ImplicitPackageReference)' != '' And '@(_OverridingPackageReference)' != ''"
142
+ />
143
+
144
+ <!-- Add the override item back -->
145
+ <PackageReference Include =" @(_OverridingPackageReference)"
146
+ Condition =" '@(_ImplicitPackageReference)' != '' And '@(_OverridingPackageReference)' != ''" />
147
+ </ItemGroup >
148
+ </Target >
149
+
115
150
<UsingTask TaskName =" CheckForDuplicateItems" AssemblyFile =" $(MicrosoftNETBuildTasksAssembly)" />
116
151
117
152
<Target Name =" CheckForDuplicateItems" BeforeTargets =" _CheckForInvalidConfigurationAndPlatform;CoreCompile" >
0 commit comments