5

The following warning has suddenly turned up on my C# .Net Framework 4.8 app. I have deleted all bin and obj folders, and I've tried removing and installing the DotNetCompilerPlatfrom package, but the message keeps appearing. Any ideas?

\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets(13,9): message : MSB4120: Item 'RoslynCompilerFiles' definition within target references itself via (qualified or unqualified) metadatum 'RecursiveDir'. This can lead to unintended expansion and cross-applying of pre-existing items. More info: https://aka.ms/msbuild/metadata-self-ref
\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets(13,9): message : MSB4120: Item 'RoslynCompilerFiles' definition within target references itself via (qualified or unqualified) metadatum 'Filename'. This can lead to unintended expansion and cross-applying of pre-existing items. More info: https://aka.ms/msbuild/metadata-self-ref
\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets(13,9): message : MSB4120: Item 'RoslynCompilerFiles' definition within target references itself via (qualified or unqualified) metadatum 'Extension'. This can lead to unintended expansion and cross-applying of pre-existing items. More info: https://aka.ms/msbuild/metadata-self-ref

(I've removed the specific directory information from the error)

Clicking the error shows the XML below, but that is part of the package so I'm lost as to how it is suddenly showing up as a warning.

<Target Name="SetRoslynCompilerFiles" >
    <Message Text="Using Roslyn from '$(RoslynToolPath)' folder" />
    <ItemGroup>
      <RoslynCompilerFiles Include="$(RoslynToolPath)\*">
        <Link>roslyn\%(RecursiveDir)%(Filename)%(Extension)</Link>  <---- Error line
      </RoslynCompilerFiles>
    </ItemGroup>
  </Target>

The full xml is found here:

\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets
Simon Parker
  • 1,656
  • 15
  • 37
  • 4
    Seeing the same messages in the past couple days whenever I build my solution since updating VS 2022 to the latest (17.7.1). – JohnnyHK Aug 17 '23 at 21:36
  • @JohnnyHK I didn't think of the update. Yes, I updated recently. It may well have started then. – Simon Parker Aug 18 '23 at 02:23

2 Answers2

11

The fix is posted here:

Remove these lines:

<RoslynCompilerFiles Include="$(RoslynToolPath)\*">
    <Link>roslyn\%(RecursiveDir)%(Filename)%(Extension)</Link>
</RoslynCompilerFiles>

Add these lines instead:

<RoslynCompilerFiles Include="$(RoslynToolPath)\**\*" />

https://github.com/aspnet/RoslynCodeDomProvider/issues/154

Lenard Bartha
  • 348
  • 1
  • 9
0

Make sure that all NuGet packages in your project are up to date, especially the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package. You can do this by right-clicking on the project in Solution Explorer and selecting "Manage NuGet Packages". Update all packages to their latest versions.

or youcan try, temporarily remove the package: As a temporary measure for debugging purposes, you could try temporarily removing the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package from your project to see if the warning goes away. If the warning disappears, it could indicate a problem specific to that package version.

erray
  • 16
  • 2
  • I had already updated everything (sorry, I forgot to note that in my question). Given this is the latest stable version, I would expect more people to be having the problem if it was the package specifically. I was hoping someone else had seen this. – Simon Parker Aug 16 '23 at 23:51
  • I am having this problem as well, even after updating all packages. It suddenly arrived after installing VS Pro Version 17.7.2. Editing the target wont help because that is part of the external package which means the problem will persist on CI/CD – Dan Aug 29 '23 at 08:53