Roslyn warning compiling .Net Framework app
Asked Answered
N

2

18

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
Necropsy answered 16/8, 2023 at 6:31 Comment(2)
Seeing the same messages in the past couple days whenever I build my solution since updating VS 2022 to the latest (17.7.1).Needlefish
@Needlefish I didn't think of the update. Yes, I updated recently. It may well have started then.Necropsy
D
34

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

Dominicadominical answered 18/8, 2023 at 4:11 Comment(3)
Excellent, fixed the issue for me as well. Like @Needlefish this started after I upgraded to VS 2022 v17.7.1Bertha
I am having this problem as well, even after updating all packages. It suddenly arrived after installing VS Pro Version 17.7.2. Really hope that your PR gets merged and a new version released soon as editing the target manually doesnt resolve the issue for CI/CDRexanna
Whilst this tweak seems to resolve the warning, I would prefer to await an upstream fix than go hacking about in static library files.Caernarvonshire
C
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.

Cull answered 16/8, 2023 at 7:40 Comment(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.Necropsy
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/CDRexanna

© 2022 - 2024 — McMap. All rights reserved.