Skip to content

Commit 79c6a1f

Browse files
Copilotjjonescz
andcommitted
Move EmbedInBinlog for EditorConfigFiles into _BeforeVBCSCoreCompile target and add test
Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
1 parent e5ede2f commit 79c6a1f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
<PropertyGroup Condition="'$(UseSharedCompilation)' == ''">
5858
<UseSharedCompilation>true</UseSharedCompilation>
5959
</PropertyGroup>
60+
61+
<!-- Embed EditorConfigFiles into the binary log. This is done here (rather than a static ItemGroup)
62+
to ensure EditorConfigFiles added by analyzer packages in BeforeTargets="CoreCompile" targets
63+
(e.g. NetAnalyzers, CodeStyle) are captured. -->
64+
<ItemGroup>
65+
<EmbedInBinlog Include="@(EditorConfigFiles)" />
66+
</ItemGroup>
6067
</Target>
6168

6269
<!--
@@ -145,7 +152,6 @@
145152
<GlobalAnalyzerConfigFiles Include="@(_AllDirectoriesAbove->'%(FullPath)'->Distinct()->Combine('.globalconfig'))" Condition="'$(DiscoverGlobalAnalyzerConfigFiles)' != 'false'" />
146153
<EditorConfigFiles Include="@(GlobalAnalyzerConfigFiles->Exists())" Condition="'$(DiscoverGlobalAnalyzerConfigFiles)' != 'false'" />
147154

148-
<EmbedInBinlog Include="@(EditorConfigFiles)" />
149155
</ItemGroup>
150156

151157
<!--

src/Compilers/Core/MSBuildTaskTests/DotNetSdkTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,5 +654,44 @@ public void TestGlobalConfigsCanBeManuallyAdded()
654654
"mycustom.config"
655655
}));
656656
}
657+
658+
[ConditionalFact(typeof(DotNetSdkAvailable), typeof(WindowsOnly), Reason = "https://github.com/dotnet/roslyn/issues/61017")]
659+
public void TestEditorConfigFilesAddedByAnalyzerPackagesAreEmbeddedInBinlog()
660+
{
661+
// Simulate the behavior of analyzer packages (e.g., NetAnalyzers, CodeStyle) that add
662+
// EditorConfigFiles in a target that runs BeforeTargets="CoreCompile". Verify those files
663+
// are included in @(EmbedInBinlog) so they are captured in the binary log.
664+
var srcFile = ProjectDir.CreateFile("lib1.cs").WriteAllText("class C { }");
665+
var analyzerGlobalConfig = ProjectDir.CreateFile("analyzer.globalconfig").WriteAllText(@"is_global = true
666+
some_prop = some_val");
667+
668+
VerifyValues(
669+
customProps: @"
670+
<PropertyGroup>
671+
<!-- Disable automatic global .editorconfig generation by the SDK -->
672+
<GenerateMSBuildEditorConfigFile>false</GenerateMSBuildEditorConfigFile>
673+
</PropertyGroup>",
674+
customTargets: $@"
675+
<!-- Simulate an analyzer package (e.g. NetAnalyzers) adding an EditorConfigFile
676+
in a target that runs before CoreCompile. -->
677+
<Target Name=""AddAnalyzerPackageEditorConfigFile"" BeforeTargets=""CoreCompile"">
678+
<ItemGroup>
679+
<EditorConfigFiles Include=""{analyzerGlobalConfig.Path}"" />
680+
</ItemGroup>
681+
</Target>",
682+
targets: new[]
683+
{
684+
"CoreCompile"
685+
},
686+
expressions: new[]
687+
{
688+
"@(EmbedInBinlog)"
689+
},
690+
expectedResults: AppendExtraEditorConfigs(new[]
691+
{
692+
Path.Combine(ProjectDir.Path, ".editorconfig"),
693+
analyzerGlobalConfig.Path
694+
}));
695+
}
657696
}
658697
}

0 commit comments

Comments
 (0)