Skip to content

CompilerVisibleProperty fails to escape special characters (# and ;) #51692

@m0sa

Description

@m0sa

Version Used:
5.0.103

Steps to Reproduce:

  1. In a csproj which consumes a configurable analyzer / generator, add
    <PropertyGroup>
      <Foo>Foo;Bar</Foo>
     <!-- I've also tried this, w/o success
       <Foo_>Foo;Bar</Foo>
       <Foo>$([MSBuild]::Escape('$(Foo_)'))</Foo>
      -->
    </PropertyGroup>
    <ItemGroup>
     <CompilerVisibleProperty Include="Foo" />
    </ItemGroup>
  2. In the analyzer
    AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.Foo", out string value)

Expected Behavior:
value should contain the whole value - "Foo;Bar"

Actual Behavior:
value contains only "Foo", ;Bar is escaped as an .INI comment


I've dug around a bit, and the issue seems to be in how the parameters are being passed to WriteAllLines here:

<WriteLinesToFile Lines="$(_GeneratedEditorConfigFileContent)" File="$(GeneratedMSBuildEditorConfigFile)" Overwrite="True" WriteOnlyWhenDifferent="True" />

It unescapes the _GeneratedEditorConfigFileContent value even if it's (manually) escaped:

Binlog:
build

Generated editorconfig:
editorconfig content

Analyzer execution:
analyzer

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions