Roslyn analysers

Add-in Express™ Support Service
That's what is more important than anything else

Roslyn analysers
 
Subscribe
Xavier N




Posts: 11
Joined: 2023-09-27
I'm a little bit confused about roslyn analysers used for code analysis..

At present my project got an "Analysers" reference. I suppose this a reference meaning old Legacy analysers (based on rulesets) but i'm not sure. In .Net 6 project, properties dialog box is different and "Analysers" reference displays a treenode with a list of analysers...

MS say
".NET analyzers are target-framework agnostic. That is, your project does not need to target a specific .NET implementation. The analyzers work for projects that target .NET 5+ as well as earlier .NET versions, such as .NET Core 3.1 and .NET Framework 4.7.2. However, to enable code analysis using the EnableNETAnalyzers property, your project must reference a project SDK"
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?tabs=net-8

To do this on a test ADX project, i tried to reference a "project SDK" modifying my .csproj/.vbproj file and adding a Sdk Name="Microsoft.NET.Sdk" section (cf. https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview)

<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Sdk Name="Microsoft.NET.Sdk" />

When i reload my project i got the new properties dialog box (as used on .Net6 project. )
But when i try to build it got a compile error

1>------ Rebuild All started: Project: MyAddin26, Configuration: Debug Any CPU ------
1>C:\Users\Xavier\Mon Projet\Program\MyAddin26\MyAddin26\MyAddin26.vbproj(4,3): warning MSB4011: "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Microsoft.Common.props" cannot be imported again. It was already imported at "C:\Program Files\dotnet\sdk\8.0.101\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (88,3)". This is most likely a build authoring error. This subsequent import will be ignored.
1>C:\Program Files\dotnet\sdk\8.0.101\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3): warning MSB4011: "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.VisualBasic.targets" cannot be imported again. It was already imported at "C:\Users\Xavier\Mon Projet\Program\MyAddin26\MyAddin26\MyAddin26.vbproj (141,3)". This is most likely a build authoring error. This subsequent import will be ignored.
1>C:\Program Files\dotnet\sdk\8.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(190,5): error NETSDK1022: Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'AddinModule.Designer.vb'; 'AddinModule.vb'; 'Form1.Designer.vb'; 'Form1.vb'; 'My Project\Application.Designer.vb'; 'My Project\AssemblyInfo.vb'; 'My Project\Resources.Designer.vb'; 'My Project\Settings.Designer.vb'
1>Done building project "MyAddin26.vbproj" -- FAILED.


I'm confused about all this and i would like to know if you have any recommandations concerning code analysis in ADX project using VS...
- Do you recommand migrating a to .Net analysers (using Nuget packages ? using .Net sdk ? - how to configure it) or do you recommand to stay with the rulesets ?

Regards, Xavier
Posted 10 Feb, 2024 08:59:03 Top
Andrei Smolin


Add-in Express team


Posts: 18833
Joined: 2006-05-11
Hello Xavier,

Xavier N writes:
The analyzers work for projects that target .NET 5+ as well as earlier .NET versions, such as .NET Core 3.1 and .NET Framework 4.7.2. However, to enable code analysis using the EnableNETAnalyzers property, your project must reference a project SDK"


Only .NET Framework versions and the old project format are supported. Note that the new project format doesn't allow registering the add-in project for COM Interop. Consider moving business logic to a separate assembly and testing that assembly as required. Before doing this, create a test add-in and check whether this schema works.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Feb, 2024 15:00:02 Top
Xavier N




Posts: 11
Joined: 2023-09-27
Thanks for your answer Andrei, i will have a try in this direction..
Regards,
Xavier
Posted 13 Feb, 2024 07:23:31 Top