SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
Other
798 stars 229 forks source link

compiling Sonarcsharp plugin giving error #1584

Closed vickyrocky closed 6 years ago

vickyrocky commented 6 years ago

I am trying to modify plugin and as per documentation i followed steps:

mvn clean install -P local-analyzer -D analyzer.configuration=Debug

Then modified sonaranalyzer-dotnet/src/sonaranalyzer.csharp/rules But while editing it is giving error: 1.import org.sonarsource.dotnet.protobuf can't be resolved and when i checked this protobuf directory, it is empty. 2.while compiling it is giving error in eclipse:

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (copy-analyzer-data) on project sonar-csharp-plugin: An Ant BuildException has occured: C:\Users\abc\Downloads\sonar-csharp-7.3.0.5690\sonar-csharp-7.3.0.5690\sonaranalyzer-dotnet\src\SonarAnalyzer.Vsix\bin\Release does not exist.

[ERROR] around Ant part ...... @ 4:150 in C:\Users\abc\Downloads\sonar-csharp-7.3.0.5690\sonar-csharp-7.3.0.5690\sonar-csharp-plugin\target\antrun\build-main.xml [ERROR] -> [Help 1]

Evangelink commented 6 years ago

Hi @vickyrocky,

I agree that the documentation I wrote isn't really precise (this was mainly intended for internal use at first and so was assuming some knowledge). In order to build the plugin relying on the local analyzer you will need to either:

Please let me know if you still encounter some issue.

vickyrocky commented 6 years ago

Hi @Evangelink I ran this msbuild /t:rebuild .\sonaranalyzer-dotnet\SonarAnalyzer.sln and getting this error: error MSB4041 : The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.micro soft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.

Also i have modified other plugin(like SonarWeb,SonarTS,SonarJava,SonarJS) as well but i am not able to understand the complete architecture of this plugin as there are no proper document so can you please guide me or refer any document for modifying this plugin if needed with details like:

I know it's a lot to ask but if you can help, i will be very thankful to you.

Evangelink commented 6 years ago

Which version of msbuild are you using? We are relying on VS 2017 / MSBuild 15.

vickyrocky commented 6 years ago

now i am using MSBuild 15 but getting this error:

C:\Users\abc\Downloads\sonar-csharp-7.2.0.5463\sonar-csharp-7.2.0.5463\sonaranalyzer-dotnet\src\SonarAnalyzer.Vsix \SonarAnalyzer.Vsix.csproj(142,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. T he missing file is ....\packages\Microsoft.VSSDK.BuildTools.15.5.72\build\Microsoft.VSSDK.BuildTools.props.

"C:\Users\abc\Downloads\sonar-csharp-7.2.0.5463\sonar-csharp-7.2.0.5463\sonaranalyzer-dotnet\SonarAnalyzer.sln" (r ebuild target) (1) -> "C:\Users\abc\Downloads\sonar-csharp-7.2.0.5463\sonar-csharp-7.2.0.5463\sonaranalyzer-dotnet\src\SonarAnalyzer.Vsi x\SonarAnalyzer.Vsix.csproj" (Rebuild target) (2) -> (EnsureNuGetPackageBuildImports target) -> C:\Users\abc\Downloads\sonar-csharp-7.2.0.5463\sonar-csharp-7.2.0.5463\sonaranalyzer-dotnet\src\SonarAnalyzer.Vs ix\SonarAnalyzer.Vsix.csproj(142,5): error : This project references NuGet package(s) that are missing on this computer . Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ....\packages\Microsoft.VSSDK.BuildTools.15.5.72\build\Microsoft.VSSDK.BuildTools.props.

Also while running this command(SonarAnalyzer.RuleDescriptorGenerator.exe cs) i am getting this error:

'SonarAnalyzer.RuleDescriptorGenerator.exe' is not recognized as an internal or external command, operable program or batch file.

vickyrocky commented 6 years ago

Hi @Evangelink ,

While running this .\scripts\build\dev-build.ps1 -restore -build -metadata , i am getting this two errors. Can you please help as this is wrt to some missing files.Thanks in advance!

I am using sonar-csharp-7.3.0.5690.

CSC : error CS2001: Source file 'C:\Users\abc\Downloads\sonar-csharp-7.3.0.5690\sonar-csharp-7.3.0.5690\sonaranalyzer-dotnet\src\SonarAnalyzer.Common\Protobuf\Ucfg.cs' could not be found.

CSC : error CS2001: Source file 'C:\Users\abc\Downloads\sonar-csharp-7.3.0.5690\sonar-csharp-7.3.0.5690\sonaranalyzer-dotnet\src\SonarAnalyzer.Common\Protobuf\AnalyzerReport.cs' could not be found.

vickyrocky commented 6 years ago

Errors got resolved when i copied sonar-ucfg folder manually inside the sonar-csharp-7.3.0.5690 directory although it was not mentioned any where in the document. But i would appreciate if @Evangelink you can maintain proper doc for developer so it will be easy for other people who wants to contribute or modify the plugin.

Thanks for your valuable response!

Evangelink commented 6 years ago

Hi @vickyrocky,

I might be missing something but most likely you forgot to do a submodule init (as stated in the doc).

vickyrocky commented 6 years ago

Hi @Evangelink ,

Oh i forgot to do that. Sorry my fault as i am naive to this.

Evangelink commented 6 years ago

No problem! Please let me know if there is anything missing to help you build on your machine.

vickyrocky commented 6 years ago

Just one help @Evangelink i need one more info for adding my own rule, i added that file to /sonaranalyzer-dotnet/src/SonarAnalyzer.CSharp/Rules and test file to sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules but how to run test and what are all the files needed to add for adding new rule apart from RSPEC_key.html and RSPEC_key.json. I will really appreciate your help on this.

Evangelink commented 6 years ago

Hi @vickyrocky,

Are you trying to add a rule that you want to contribute back? Or are you trying to have a custom analyzer you will use internally?

vickyrocky commented 6 years ago

Hi @Evangelink ,

I would like to contribute back if rule is approved by community but before that i will be using internally according to my current requirement. So will it make any difference if using custom analyzer?

vickyrocky commented 6 years ago

Hi @Evangelink,

I am also getting this error while building in eclipse:

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (copy-analyzer-data) on project sonar-csharp-plugin: An Ant BuildException has occured: C:\Users\abc\Downloads\original\sonar-csharp-7.3.1.5982\sonar-csharp-7.3.1.5982\sonaranalyzer-dotnet\src\SonarAnalyzer.Vsix\bin\Release does not exist. [ERROR] around Ant part ...... @ 4:159 in C:\Users\abc\Downloads\original\sonar-csharp-7.3.1.5982\sonar-csharp-7.3.1.5982\sonar-csharp-plugin\target\antrun\build-main.xml [ERROR] -> [Help 1]

Can you please help to resolve this error? Thanks in advance!

Evangelink commented 6 years ago

Hi @vickyrocky,

By default the compilation uses the Release mode (i.e. mvn clean install == mvn clean install -P local-analyzer -D analyzer.configuration=Release). So you need to build the C# analyzer in Release mode (i.e. .\scripts\build\dev-build.ps1 -restore -build -metadata -release`)

vickyrocky commented 6 years ago

Hi @Evangelink ,

Thanks got it. But how to run test for new rules in sonaranalyzer-dotnet?

Evangelink commented 6 years ago

Everything is explained in the different docs: https://github.com/SonarSource/sonar-csharp/blob/master/docs/contributing-analyzer.md https://github.com/SonarSource/sonar-csharp/blob/master/docs/contributing-plugin.md

vickyrocky commented 6 years ago

Thank you for your help @Evangelink . I also appreciate your patience during the same.

kumardharm commented 5 years ago

@Evangelink
Hello, I tried both the process, but no luck. Can you please guide me

Scenario 1: Through maven After running mvn clean install -P local-analyzer -D analyzer.configuration=Release or mvn clean install -P local-analyzer -D analyzer.configuration=Debug

I am getting below error: \Sonar\c#\sonar-dotnet\sonaranalyzer-dotnet\src\SonarAnalyzer.Vsix\bin\Release does not exist. [ERROR] around Ant part ...... @ 4:124 in C:\Users\dharkuma\Documents\Sonar\c#\sonar-dotnet\sonar-csharp-plugin\target\antrun\build-main.xml

Scenario 2: Through Powershell .\scripts\build\dev-build.ps1 -restore -build -metadata

I am getting below error: ailed to locate executable 'vswhere.exe' on the path

Evangelink commented 5 years ago

Hi @kumardharm,

In scenario 1, have you built the analyzer before running this command? It should look like:

msbuild /t:rebuild /p:Configuration=Release .\sonaranalyzer-dotnet\SonarAnalyzer.sln
mvn clean install -P local-analyzer -D analyzer.configuration=Release

or

msbuild /t:rebuild .\sonaranalyzer-dotnet\SonarAnalyzer.sln
mvn clean install -P local-analyzer -D analyzer.configuration=Debug

In scenario 2, as explained by the error, the script requires vswhere.exe to be in the path. See https://github.com/Microsoft/vswhere