Skip to content

Commit

Permalink
Simplify target to enable config binding src generator and rename sen…
Browse files Browse the repository at this point in the history
…tinel property
  • Loading branch information
layomia committed Apr 5, 2023
1 parent 66211eb commit 95270a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 53 deletions.
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,12 @@

<PropertyGroup>
<IncludeMultiTargetRoslynComponentTargets>false</IncludeMultiTargetRoslynComponentTargets>
<RoslynComponentsAreOffByDefault>true</RoslynComponentsAreOffByDefault>
<EnableConfigurationBindingGeneratorTargetsFilePath>buildTransitive\EnableConfigurationBindingGenerator.targets</EnableConfigurationBindingGeneratorTargetsFilePath>
</PropertyGroup>

<ItemGroup>
<Content Include="$(EnableConfigurationBindingGeneratorTargetsFilePath)" PackagePath="buildTransitive\netstandard2.0\$(PackageId).targets" />
<Content Include="$(EnableConfigurationBindingGeneratorTargetsFilePath)" PackagePath="buildTransitive\$(NetCoreAppMinimum)\$(PackageId).targets" />
<Content Include="$(EnableConfigurationBindingGeneratorTargetsFilePath)" PackagePath="buildTransitive\$(NetFrameworkMinimum)\$(PackageId).targets" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>
<Target Name="_Microsoft_Extensions_Configuration_BinderGatherAnalyzers">
<ItemGroup>
<_Microsoft_Extensions_Configuration_BinderAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'Microsoft.Extensions.Configuration.Binder'" />
</ItemGroup>
</Target>

<Target Name="_Microsoft_Extensions_Configuration_BinderRemoveAnalyzer"
Condition="'$(EnableConfigurationBindingGenerator)' != 'true'"
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
DependsOnTargets="_Microsoft_Extensions_Configuration_BinderGatherAnalyzers">

<ItemGroup>
<Analyzer Remove="@(_Microsoft_Extensions_Configuration_BinderAnalyzer)" />
</ItemGroup>
</Target>
</Project>

0 comments on commit 95270a9

Please sign in to comment.