Search code examples
c#.netroslyn.net-4.8

Roslyn warning compiling .Net Framework app


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

Solution

  • 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