4
votes

In my .Net Framework (C#) solution I use some Roslyn analyzers, whose settings I tuned in a .editorconfig file.

When I build locally my solution in VS2019 I get no warnings from the analyzers.

When I build the solution in a Azure DevOps pipeline task, Roslyn related warnings are generated:

build task warning in build task

It seems to me that the DevOps pipeline task ignores the settings in the .editorconfig file. How can I make the pipeline task consider the .editorconfig file settings?

2
Hi, is there any update for this issue? Please check if my answer helps to resolve your issue or not :)LoLance
I have the same issue @LanceLi-MSFT. I'm trying to exclude generated code from code analysis. Works in Visual Studio but not in Azure Pipelines. .editorconfig is in same folder as csproj. Contents look like [Generated/**/*.cs] dotnet_analyzer_diagnostic.severity = noneDustin Metzgar
@LanceLi-MSFT we're using microsoft-hosted Ubuntu 18.04 agentsDustin Metzgar

2 Answers

3
votes

How can I make the pipeline task consider the .editorconfig file settings?

We don't need to manually set anything about .editorconfig in pipeline, it would work automatically when it's placed under project folder. I've just tested it both in local machine and build pipeline, it should work.

So you should:

1.Navigate to Azure Devops Repos to check if the .editorconfig file exists in same folder with xx.csproj file. Pay attention to the branch you choose, make sure the branch you use to run build pipeline do have the .editorconfig file.

2.Check the content of .editorconfig file, check if it contains statements like this:

# SA1633: File should have header
dotnet_diagnostic.SA1633.severity = none

Your .editorconfig file won't suppress those warnings unless it contains this kind of definitions.

3.Try using different agents, I assume you're using self-agent. Which means you're calling your local VS instance to run the job and maybe there's something wrong with that. I suggest you can try running it with microsoft-hosted agent(choose windows-latest), it works well in my side. Also, update your local VS to latest version if you continue to do it using self-agent.

4.Specify the version of nuget.exe, 4.4.0 is too old. Try using 5.3.1 and above.

Hope all above helps :)

1
votes

We ran into a similar problem today, and discovered that MSBuild 16.9 prioritizes code analysis ruleset files over .editorconfig files. So if your project refers to a ruleset that sets a rule to be an Error, but your editorconfig changes it to be a suggestion or warning, it will still treat things as an error.

Since Azure DevOps updated the version of MSBuild to 16.9, while we were still using 16.8, we had different behaviors on our local machines than what happened in our build pipeline.

Oddly enough, setting severity to none in the editorconfig file still seems to prevent the analyzer from complaining.