Skip to content

Commit

Permalink
[MSBuildReferences.projitems] Require opt-in to use Microsoft.Build (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
jpobst authored Nov 30, 2023
1 parent 21de3d7 commit 4889bf0
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="$(MSBuildPackageReferenceVersion)" />
<PackageReference Include="Microsoft.Build" Version="$(MSBuildPackageReferenceVersion)" Condition=" '$(_IncludeMicrosoftBuildPackage)' == 'true' " />
<PackageReference Include="Microsoft.Build.Framework" Version="$(MSBuildPackageReferenceVersion)" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MSBuildPackageReferenceVersion)" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MSBuildPackageReferenceVersion)" />
Expand Down

0 comments on commit 4889bf0

Please sign in to comment.