Skip to content
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

Intermitent build issues of MSBuild repo - xml CDATA escaping not properly interpreted #11184

Open
JanKrivanek opened this issue Dec 20, 2024 · 0 comments
Labels
Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself.

Comments

@JanKrivanek
Copy link
Member

JanKrivanek commented Dec 20, 2024

Context

Intermittent build errors of our repo indicating that xml was incorrectly parsed and 'CDATA' escaping sequence spilled over into the content

C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(1,1): error CS1525: Invalid expression term '<' [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]
C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(1,10): error CS1003: Syntax error, ']' expected [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]
C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(1,10): error CS1002: ; expected [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]
C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(10,7): error CS1022: Type or namespace definition, or end-of-file expected [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]
C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(10,9): error CS8803: Top-level statements must precede namespace and type declarations. [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]
C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(10,9): error CS1525: Invalid expression term '>' [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]
C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(10,10): error CS1733: Expected expression [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]
C:\src\msbuild-2\artifacts\obj\Microsoft.Build.BuildCheck.UnitTests\Debug\net472\BuildCheckUnitTestsConstants.cs(10,10): error CS1002: ; expected [C:\src\msbuild-2\src\BuildCheck.UnitTests\Microsoft.Build.BuildCheck.UnitTests.csproj::TargetFramework=net472]

Looking on the file it complains about - it realy contains unexpected xml escaping sequences:

BuildCheckUnitTestsConstants.cs:

<![CDATA[
namespace Microsoft.Build.BuildCheck.UnitTests
{
    internal sealed class BuildCheckUnitTestsConstants
    {
        public const string MicrosoftBuildPackageVersion = @"17.14.0-dev-24620-01";
        public const string RepoRoot = @"C:\src\msbuild-2\";
    }
}
      ]]>

It seems like the CDATA from the msbuild file was not properly interpreted:

<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)BuildCheckUnitTestsConstants.cs">
<PropertyGroup>
<GeneratedText>
<![CDATA[
namespace Microsoft.Build.BuildCheck.UnitTests
{
internal sealed class BuildCheckUnitTestsConstants
{
public const string MicrosoftBuildPackageVersion = @"$(Version)"%3B
public const string RepoRoot = @"$(RepoRoot)"%3B
}
}
]]>
</GeneratedText>
<GeneratedFilePath>$(IntermediateOutputPath)BuildCheckUnitTestsConstants.cs</GeneratedFilePath>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(GeneratedFilePath)" />
<FileWrites Include="$(GeneratedFilePath)" />
</ItemGroup>
<WriteLinesToFile Lines="$(GeneratedText)" File="$(GeneratedFilePath)" WriteOnlyWhenDifferent="true" Overwrite="true" />
</Target>

Repro steps

I'm not sure about specific conditions - but it appears every couple full builds. Then I need to clean the artifacts folder and issue is gone for some time

Binlog

msbuild-cdata-issue.binlog.txt

Note

This seems related to https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1980399/, https://developercommunity.visualstudio.com/t/Project-Generated-Files-Sometimes-Contai/10604117

@JanKrivanek JanKrivanek added the Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself. label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself.
Projects
None yet
Development

No branches or pull requests

1 participant