-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Repro steps
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Description>There's a bug {here}</Description>
</PropertyGroup>
</Project>dotnet build
Expected
Builds successfully
Actual
error MSB4018: The "WriteCodeFragment" task failed unexpectedly.
error MSB4018: System.FormatException: Input string was not in a correct format.
error MSB4018: at System.Text.StringBuilder.FormatError()
error MSB4018: at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
error MSB4018: at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
error MSB4018: at System.String.Format(String format, Object[] args)
error MSB4018: at Microsoft.Build.Tasks.WriteCodeFragment.GenerateCodeCoreClr(String& extension)
error MSB4018: at Microsoft.Build.Tasks.WriteCodeFragment.Execute()
The best fix for this would be to remove the CODEDOM ifdefs and use the same code as .NET Framework in .NET Core msbuild. A regression test should also be added.
Original bug description, focusing more on code inspection than scenario
By code inspection, it appears that the inputs to WriteCodeFragment inputs aren't escaped in the xplat (non-CodeDOM) implementation.
I believe this will fail if _ParameterN has text that needs to be escaped. (e.g. imagine if there are embedded quotes in the value.) EDIT: Quotes and other things were fixed in #1369, but braces are still a problem as they throw off String.Format.
I also don't understand the non-string side of that ?: expression because the CodeDOM equivalent casts unconditionally to string and why do we expect non-strings to be quoted in their ToString() output?
Spotted while investigating #935