DotNet 6 - Incremental Source Generator - AdditionalFileItemNames over written by sonar

SonarScanner for MSBuild 5.4.1
While running in a docker linux image with it

Utilizing generator logging found sonar resources were pulled in instead

/var/lib/jenkins/workspace/ci_cd_ae-project_PR-9/.sonarqube/conf/cs/SonarLint.xml <?xml version="1.0" encoding="UTF-8"?>
/var/lib/jenkins/workspace/ci_cd_ae-project_PR-9/.sonarqube/conf/30/SonarProjectConfig.xml <?xml version="1.0" encoding="utf-8"?>
/var/lib/jenkins/workspace/ci_cd_ae-project_PR-9/.sonarqube/conf/30/ProjectOutFolderPath.txt /var/lib/jenkins/workspace/ci_cd_ae-project_PR-9/.sonarqube/out/30

Locally it seems these files are just additional and you can just filter them out in the generator but unfortunately that is not working via the docker image

  • steps to reproduce
    Create a basic incremental source generator utilizing the AdditionalTextsProvider IncrementalValuesProvider
    The project using the incremental source generator needs to have the following in the csproj file
<PropertyGroup><AdditionalFileItemNames>$(AdditionalFileItemNames);EmbeddedResource</AdditionalFileItemNames>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource  Include="..\*.json" Visible="false" />
</ItemGroup>

Caveat The files are expected to be outside of the project being built folder structure →
Project.Models/jsonFiles/several files
Project.Console → Being built and will use the files from the models project

  • potential workaround
    None as far as I can tell and hoping someone has a work around.
    There is a work around, have two separate sets of code for reading files needed like the json in my case. So I check if we have the expected AdditionalText files otherwise we get the expected directory and read the files via File.ReadAllText

Hi @Mark_Chmiel - welcome to the community.

I’ve tried to repro this locally with the project in the following zip, but failed. xxx.zip (339.5 KB)

In my case, the verbose build log showed that the expected files were being passed to the compiler as additional files i.e. the Sonar files and the embedded resources (I used .txt files), so I would expect them all to be available to analyzers and source generators:

... 
 /additionalfile:d:\support\xxx\AdditFileItemNamesOverridden\.sonarqube\conf\cs\SonarLint.xml
 /additionalfile:..\AdditFileItemNamesOverridden\obj\Debug\net6.0\AddiFileItemNamesOverridden.csproj.FileListAbsolute.txt
 /additionalfile:..\AdditFileItemNamesOverridden\TextFile1.txt
 /additionalfile:..\TextFileAbove.txt
 ...

There is one quick thing you could try, which is to use Linux directory separators in your project file
i.e. <EmbeddedResource Include="../*.json" Visible="false" />

If that doesn’t work, could you share the verbose build logs please? (pass -v:d in the build step).

This topic was automatically closed after 11 days. New replies are no longer allowed.