-
When trying to use Microsoft.CodeAnalysis.CSharp.CodeStyle with Unity, I have encountered an issue. I have ensured that EnforceCodeStyleInBuild is enabled for our project, as Unity runs analyzers on builds. However, adding EnforceCodeStyleInBuild to the .csproj file has had no effect, possibly due to Unity handling .csproj files differently. I am considering reassembling Microsoft.CodeAnalysis.CSharp.CodeStyle with a different name, but I am unsure if this is a viable solution given the complexity of the Roslyn project. Can anyone provide insights on whether this approach is worth trying and if it can be done within a reasonable timeframe? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 5 replies
-
What would you be attempting to gain by renaming it? |
Beta Was this translation helpful? Give feedback.
-
@jasonmalinowski I attempt to bypass EnforceCodeStyleInBuild condition since as far as I'm aware it is hadrcoded into compiler and checks for specific namespace. Meaning if analyzer id is Microsoft.CodeAnalysis.CSharp.CodeStyle then EnforceCodeStyleInBuild would be applied to it by compiler itself. |
Beta Was this translation helpful? Give feedback.
-
In fact, I would've test with creating mock analyzer, name it Microsoft.CodeAnalysis.CSharp.CodeStyle and look at its behaviour first. |
Beta Was this translation helpful? Give feedback.
-
Ok. It seems like renaming it has no effect. I made new custom analyzer with Microsoft.CodeAnalysis.CSharp.CodeStyle name and I get errors on build. |
Beta Was this translation helpful? Give feedback.
-
Any other ideas on how to make Microsoft.CodeAnalysis.CSharp.CodeStyle work with Unity? |
Beta Was this translation helpful? Give feedback.
-
@Azirel did you follow the steps mentioned here: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?tabs=net-7#enable-on-build |
Beta Was this translation helpful? Give feedback.
-
Problem solved. Issue was in .dll version. It has to be in sync with Microsoft.CodeAnalisys.dll that unity uses under the hood. |
Beta Was this translation helpful? Give feedback.
Problem solved. Issue was in .dll version. It has to be in sync with Microsoft.CodeAnalisys.dll that unity uses under the hood.