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

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

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
@maridematte maridematte added triaged Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself. and removed Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself. labels Jan 8, 2025
@MichalPavlik
Copy link
Member

I'm not able to reproduce the issue locally. @JanKrivanek, it's probably something that depends on the environment.

@MichalPavlik MichalPavlik removed their assignment Jan 10, 2025
@JanKrivanek JanKrivanek self-assigned this Jan 20, 2025
@JanKrivanek
Copy link
Member Author

Caught this with evidence :-)

The file again appears already up to date to the batch build:

Image

In procmon I can see this was update by msbuild spawned by the VS:

Image

And the project it runs was apparently injected by ReSharper:

<Project DefaultTargets="ControllerTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <UsingTask AssemblyFile="C:\Users\jankrivanek\AppData\Local\JetBrains\Installations\ReSharperPlatformVs17_f4389299_000\JetBrains.Platform.MsBuildTask.v17.dll" TaskName="JetBrains.Platform.MsBuildTask.ControllerTask" />
 <Target Name="ControllerTarget">
  <Message Importance="High" Text="Run controller from C:\Users\jankrivanek\AppData\Local\JetBrains\Installations\ReSharperPlatformVs17_f4389299_000\JetBrains.Platform.MsBuildTask.v17.dll" />
  <ControllerTask PortValue="59648" BuildToolVersion="17.14" LoggerPath="C:\Users\jankrivanek\AppData\Local\Temp\JetLogs\MsBuildTask\2025-01-17 15-28-24Z-MsBuildTask.log" />
 </Target>
</Project>

Gowodiz.proj

And from their log linked I can see it was really trying to build the project:

18:49:42.309 |I| Build                          | :82                            | Finish build part [1/2] for project 'Microsoft.Build.BuildCheck.UnitTests.csproj': Success
18:49:43.090 |I| Build                          | :85                            | Finish build part [2/2] for project 'Microsoft.Build.BuildCheck.UnitTests.csproj': Success

That being said - the issue is in ReSharper - I'll log issue with JB

@JanKrivanek
Copy link
Member Author

While 3rd party product issue - just for consistency - unchecking the "Extensions -> ReSharper -> Options -> General -> Read solution model directly from project/solution files." reliably gets rid of the issue, while checking it reliably leads to the issue (with combination of switching branches/configs or accumulating specific changes within the inputs)

Image

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. triaged
Projects
None yet
Development

No branches or pull requests

3 participants