-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
CompilerVisibleProperty fails to escape special characters (# and ;) #51692
Comments
This is effectively a duplicate of #51625, but is occurring under very different circumstances. |
@sharwell indeed, although I stopped looking at this point. Seems like in order for a full round-trip with special characters to work, there would need to be a well defined escaping spec (which seems to be missing now, the value is passed on and parsed as-is). There are actually 2 bugs here:
|
Here's the workaround I have, so I can pass strings containing arbitrary characters from csproj to analyzers: Analyzer: var foo =
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.Foo", out var foo64)
&& !string.IsNullOrWhiteSpace(foo64)
? System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(foo64))
: null; .csproj consuming (and configuring) the analyzer: <ItemGroup>
<CompilerVisibleProperty Include="Foo" />
</ItemGroup>
<UsingTask TaskName="ToBase64" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<In ParameterType="System.String" Required="true" />
<Out ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="C#">Out = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(In));</Code>
</Task>
</UsingTask>
<Target Name="RoslynIssue51692Workaround" BeforeTargets="BeforeCompile" Condition=" '$(Foo)' != '' ">
<ToBase64 In="$(Foo)">
<Output TaskParameter="Out" PropertyName="Foo" />
</ToBase64>
</Target> |
@m0sa Funnily enough base64 encoding was one of the options we considered for how to route everything through the various layers correctly. @jaredpar The problem is that we take an msbuild value -> write that to .globalconfig -> read it into the compiler. There is an impedence mismatch between the way msbuild + .globalconfig handles escaping of values, meaning its possible to loose data. A simple example of this is multi-line values in msbuild. We'll lose everything after the initial line. |
Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it. |
Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it. |
I also found that having a newline in your compiler property causes the rest of the contents to spill over into the |
This is a workaround (fix?) for dotnet/roslyn#51692, basically. We lose all content after the first semicolon in constant and metadata values (presumably Git too). Project properties also suffer from this, but merits unifying it with ThisAssembly.Constants to continue to streamline the implementation.
This is a workaround (fix?) for dotnet/roslyn#51692, basically. We lose all content after the first semicolon in constant and metadata values (presumably Git too). Project properties also suffer from this, but merits unifying it with ThisAssembly.Constants to continue to streamline the implementation.
I am having the same (similar?) issue when using multiline text as a value. <CompilerVisibleProperty Include="Avro_LogicalTypes" /> and then use it as: <PropertyGroup>
<Avro_LogicalTypes>
foo : bar,
user-id:Contrib.Avro.CodeGen.Tests.UserId ,
duration:System.TimeSpan
</Avro_LogicalTypes>
</PropertyGroup> When using |
Version Used:
5.0.103
Steps to Reproduce:
Expected Behavior:
value
should contain the whole value -"Foo;Bar"
Actual Behavior:
value
contains only"Foo"
,;Bar
is escaped as an .INI commentI've dug around a bit, and the issue seems to be in how the parameters are being passed to WriteAllLines here:
roslyn/src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets
Line 150 in 0aaa2eb
It unescapes the
_GeneratedEditorConfigFileContent
value even if it's (manually) escaped:Binlog:
Generated editorconfig:
Analyzer execution:
The text was updated successfully, but these errors were encountered: