Skip to content
Open
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
4 changes: 2 additions & 2 deletions eng/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<!--
MSBuild - need to use older packages when targeting net8.0 since the newer versions only support net472 and net9.0.
When tareting the latest .NET the version must also be lower or equal to one specified in
When targeting the latest .NET the version must also be lower or equal to one specified in
https://github.com/dotnet/sdk/blob/main/src/Layout/redist/minimumMSBuildVersion#L1
-->

Expand Down Expand Up @@ -314,7 +314,7 @@
Infra
-->
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="MSBuild.StructuredLogger" Version="2.3.71" />
<PackageVersion Include="MSBuild.StructuredLogger" Version="2.3.113" />
<PackageVersion Include="Mono.Options" Version="6.6.0.161" />
<PackageVersion Include="Roslyn.Diagnostics.Analyzers" Version="$(RoslynDiagnosticsAnalyzersPackageVersion)" />
<PackageVersion Include="SourceBrowser" Version="1.0.21" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
@(CustomAdditionalCompileOutputs)"
Returns="@(CscCommandLineArgs)"
DependsOnTargets="$(CoreCompileDependsOn);_BeforeVBCSCoreCompile">

<!-- Embed EditorConfigFiles into the binary log. This is done here (inside CoreCompile rather than
a static ItemGroup) to ensure EditorConfigFiles added by analyzer packages in
BeforeTargets="CoreCompile" targets (e.g. NetAnalyzers, CodeStyle) are captured. -->
<ItemGroup>
<EmbedInBinlog Include="@(EditorConfigFiles)" />
</ItemGroup>

<!-- These two compiler warnings are raised when a reference is bound to a different version
than specified in the assembly reference version number. MSBuild raises the same warning in this case,
so the compiler warning would be redundant. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
@(CustomAdditionalCompileOutputs)"
Returns="@(VbcCommandLineArgs)"
DependsOnTargets="$(CoreCompileDependsOn);_BeforeVBCSCoreCompile">

<!-- Embed EditorConfigFiles into the binary log. This is done here (inside CoreCompile rather than
a static ItemGroup) to ensure EditorConfigFiles added by analyzer packages in
BeforeTargets="CoreCompile" targets (e.g. NetAnalyzers, CodeStyle) are captured. -->
<ItemGroup>
<EmbedInBinlog Include="@(EditorConfigFiles)" />
</ItemGroup>

<PropertyGroup>
<_NoWarnings Condition="'$(WarningLevel)' == '0'">true</_NoWarnings>
<_NoWarnings Condition="'$(WarningLevel)' == '1'">false</_NoWarnings>
Expand Down
79 changes: 77 additions & 2 deletions src/Compilers/Core/MSBuildTaskTests/SdkIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Basic.CompilerLog.Util;
using Microsoft.Build.Logging.StructuredLogger;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using Xunit.Abstractions;
using Basic.CompilerLog.Util;

namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests;

Expand Down Expand Up @@ -200,4 +200,79 @@ End Module

ArtifactUploadUtil.SetSucceeded();
}

[ConditionalFact(typeof(DotNetSdkAvailable))]
[WorkItem("https://github.com/dotnet/roslyn/issues/82721")]
public void EditorConfig_EmbeddedInBinlog_Generated()
{
var projectFile = ProjectDir.CreateFile("console.csproj");
projectFile.WriteAllText($"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>{NetCoreTfm}</TargetFramework>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="RootNamespace" />
</ItemGroup>
</Project>
""");

ProjectDir.CreateFile("c.cs").WriteAllText("""
class C { }
""");

var binlogPath = RunBuild(projectFile.Path);

var build = BinaryLog.ReadBuild(binlogPath);

string embeddedText = build.SourceFiles
.Single(static f => f.FullPath.EndsWith("GeneratedMSBuildEditorConfig.editorconfig", StringComparison.OrdinalIgnoreCase))
.Text;

Assert.Contains("is_global = true", embeddedText);
Assert.Contains("build_property.RootNamespace", embeddedText);
ArtifactUploadUtil.SetSucceeded();
}

[ConditionalFact(typeof(DotNetSdkAvailable))]
[WorkItem("https://github.com/dotnet/roslyn/issues/82721")]
public void EditorConfig_EmbeddedInBinlog_FromTarget()
{
string analyzerGlobalConfigText = """
is_global = true
some_prop = some_val
""";
var analyzerGlobalConfig = ProjectDir.CreateFile("analyzer.globalconfig").WriteAllText(analyzerGlobalConfigText);

var projectFile = ProjectDir.CreateFile("console.csproj");
projectFile.WriteAllText($"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>{NetCoreTfm}</TargetFramework>
</PropertyGroup>

<Target Name="AddAnalyzerPackageEditorConfigFile" BeforeTargets="CoreCompile">
<ItemGroup>
<EditorConfigFiles Include="{analyzerGlobalConfig.Path}" />
</ItemGroup>
</Target>
</Project>
""");

ProjectDir.CreateFile("c.cs").WriteAllText("""
class C { }
""");

var binlogPath = RunBuild(projectFile.Path);

var build = BinaryLog.ReadBuild(binlogPath);

string embeddedText = build.SourceFiles
.Single(f => f.FullPath.Equals(analyzerGlobalConfig.Path, StringComparison.OrdinalIgnoreCase))
.Text;

Assert.Equal(analyzerGlobalConfigText, embeddedText);
ArtifactUploadUtil.SetSucceeded();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ private static void EmitTestHelperTargets(
<!-- Overwrite CoreCompile target to avoid triggering the compiler -->
<Target Name=""CoreCompile""
DependsOnTargets=""$(CoreCompileDependsOn);_BeforeVBCSCoreCompile"">
<ItemGroup>
<EmbedInBinlog Include=""@(EditorConfigFiles)"" />
</ItemGroup>
</Target>
<Target Name=""InitializeSourceControlInformation""/>
Expand Down