Skip to content

Simplify target to enable config binding src generator from NuGet package, ensure it runs for all TFMs, and rename enabling property #84379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions eng/OffByDefaultRoslynComponent.targets.template

This file was deleted.

35 changes: 0 additions & 35 deletions eng/packaging.targets
Original file line number Diff line number Diff line change
Expand Up @@ -193,41 +193,6 @@
Overwrite="true" />
</Target>

<PropertyGroup>
<_OffByDefaultRoslynComponentTargetsTemplate>$(MSBuildThisFileDirectory)OffByDefaultRoslynComponent.targets.template</_OffByDefaultRoslynComponentTargetsTemplate>
<OffByDefaultRoslynComponentTargetsFileIntermediatePath>$(IntermediateOutputPath)OffByDefaultRoslynComponent.targets</OffByDefaultRoslynComponentTargetsFileIntermediatePath>
<RoslynComponentsAreOffByDefault Condition="'$(RoslynComponentsAreOffByDefault)' == ''">false</RoslynComponentsAreOffByDefault>
</PropertyGroup>

<!-- In packages that contain Analyzers that are off by default, include a .targets file that will exclude the analyzer. -->
<Target Name="ExcludeOffByDefaultRoslynComponentTargetsInPackage"
AfterTargets="IncludeAnalyzersInPackage"
Condition="'@(ProjectReference)' != '' and
@(ProjectReference->AnyHaveMetadataValue('PackAsAnalyzer', 'true')) and
'$(RoslynComponentsAreOffByDefault)' == 'true'"
DependsOnTargets="GenerateOffByDefaultRoslynComponentTargetsFile">
<ItemGroup>
<Content Include="$(OffByDefaultRoslynComponentTargetsFileIntermediatePath)" PackagePath="buildTransitive\netstandard2.0\$(PackageId).targets" />
<Content Include="$(OffByDefaultRoslynComponentTargetsFileIntermediatePath)" PackagePath="buildTransitive\%(NETStandardCompatError.Supported)\$(PackageId).targets" Condition="'@(NETStandardCompatError)' != ''" />
</ItemGroup>
</Target>

<Target Name="GenerateOffByDefaultRoslynComponentTargetsFile"
Inputs="$(MSBuildProjectFullPath);$(_OffByDefaultRoslynComponentTargetsTemplate)"
Outputs="$(OffByDefaultRoslynComponentTargetsFileIntermediatePath)">
<PropertyGroup>
<_OffByDefaultRoslynComponentTargetPrefix>$(PackageId.Replace('.', '_'))</_OffByDefaultRoslynComponentTargetPrefix>
<EnableSourceGeneratorPropertyName Condition="'$(EnableSourceGeneratorPropertyName)' == ''">Enable$(PackageId.Replace('.', ''))SourceGenerator</EnableSourceGeneratorPropertyName>
</PropertyGroup>

<WriteLinesToFile File="$(OffByDefaultRoslynComponentTargetsFileIntermediatePath)"
Lines="$([System.IO.File]::ReadAllText('$(_OffByDefaultRoslynComponentTargetsTemplate)')
.Replace('{TargetPrefix}', '$(_OffByDefaultRoslynComponentTargetPrefix)')
.Replace('{NuGetPackageId}', '$(PackageId)')
.Replace('{EnableSourceGeneratorPropertyName}', '$(EnableSourceGeneratorPropertyName)'))"
Overwrite="true" />
</Target>

<!-- Add targets file that marks a .NETStandard applicable tfm as unsupported. -->
<Target Name="AddNETStandardCompatErrorFileForPackaging"
Condition="'@(NETStandardCompatError)' != '' and '$(DisableNETStandardCompatErrors)' != 'true'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

<PropertyGroup>
<IncludeMultiTargetRoslynComponentTargets>false</IncludeMultiTargetRoslynComponentTargets>
<RoslynComponentsAreOffByDefault>true</RoslynComponentsAreOffByDefault>
<DisableNETStandardCompatErrors>true</DisableNETStandardCompatErrors>
</PropertyGroup>

<ItemGroup>
<Content Include="buildTransitive\$(PackageId).targets" PackagePath="buildTransitive\netstandard2.0\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project InitialTargets="NETStandardCompatError_Microsoft_Extensions_Configuration_Binder">
<Target Name="_Microsoft_Extensions_Configuration_BinderRemoveAnalyzer"
Condition="'$(EnableConfigurationBindingGenerator)' != 'true'"
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets">

<ItemGroup>
<Analyzer Remove="@(Analyzer->WithMetadataValue('NuGetPackageId', 'Microsoft.Extensions.Configuration.Binder'))" />
</ItemGroup>
</Target>

<Target Name="NETStandardCompatError_Microsoft_Extensions_Configuration_Binder"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please file a tracking issue to discuss how to support both the NETStandardCompatError infrastructure and target framework agnostic msbuild infrastructure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you go: #84570.

Condition="'$(SuppressTfmSupportBuildWarnings)' == ''">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to '$(SuppressTfmSupportBuildWarnings)' != 'true'. While at it, can you please also change that here:

Condition="'%24(SuppressTfmSupportBuildWarnings)' == ''">

<PropertyGroup>
<_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp2.0')) AND
!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))"
>net6.0</_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework>
<_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net461')) AND
!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net462'))"
>net462</_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework>
</PropertyGroup>
<Warning Condition="'$(_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework)' != ''"
Text="Microsoft.Extensions.Configuration.Binder doesn't support $(TargetFramework) and has not been tested with it. Consider upgrading your TargetFramework to $(_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework) or later. You may also set &lt;SuppressTfmSupportBuildWarnings&gt;true&lt;/SuppressTfmSupportBuildWarnings&gt; in the project file to ignore this warning and attempt to run in this unsupported configuration at your own risk." />
</Target>
</Project>