Skip to content

Commit b1f795e

Browse files
jpobstpjcollins
authored andcommitted
[MSBuildReferences.projitems] Require opt-in to use Microsoft.Build (#220)
Projects that import `MSBuildReferences.projitems` receive a `@(PackageReference)` to the `Microsoft.Build` NuGet package. However, many consumers have `$(TargetFramework)`=netstandard2.0, and the `Microsoft.Build` package does not have support netstandard2.0, resulting in the following warnings: Warning NU1701 Package 'Microsoft.Build 17.3.2' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. Warning NU1701 Package 'Microsoft.IO.Redist 6.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. Most consumers do not actually need this package, so we can make it opt-in to prevent the warnings and extra dependencies in those projects. Packages opt-in to referencing the `Microsoft.Build` package by setting the `$(_IncludeMicrosoftBuildPackage)` MSBuild property to true: <_IncludeMicrosoftBuildPackage>true</_IncludeMicrosoftBuildPackage> Note: this will be a "breaking" change to an unknown amount of consumers. We're crossing our fingers that this won't break too much. Enabling this change fixes 226 CI warnings in xamarin-android.
1 parent d50747c commit b1f795e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Microsoft.Android.Build.BaseTasks/MSBuildReferences.projitems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Build" Version="$(MSBuildPackageReferenceVersion)" />
14+
<PackageReference Include="Microsoft.Build" Version="$(MSBuildPackageReferenceVersion)" Condition=" '$(_IncludeMicrosoftBuildPackage)' == 'true' " />
1515
<PackageReference Include="Microsoft.Build.Framework" Version="$(MSBuildPackageReferenceVersion)" />
1616
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MSBuildPackageReferenceVersion)" />
1717
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MSBuildPackageReferenceVersion)" />

0 commit comments

Comments
 (0)