Closed vickyrocky closed 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:
Run from the folder root: .\scripts\build\dev-build.ps1 -restore -build -metadata
. Note that you can either add the -buildJava
switch after or run mvn clean install -P local-analyzer -D analyzer.configuration=Debug
Or you can do the individual commands:
msbuild /t:rebuild .\sonaranalyzer-dotnet\SonarAnalyzer.sln
cd "sonaranalyzer-dotnet\src\SonarAnalyzer.RuleDescriptorGenerator\bin\Debug\net46"
SonarAnalyzer.RuleDescriptorGenerator.exe cs
mvn clean install -P local-analyzer -D analyzer.configuration=Debug
Please let me know if you still encounter some issue.
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
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.
Which version of msbuild are you using? We are relying on VS 2017 / MSBuild 15.
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.
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.
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!
Hi @vickyrocky,
I might be missing something but most likely you forgot to do a submodule init (as stated in the doc).
Hi @Evangelink ,
Oh i forgot to do that. Sorry my fault as i am naive to this.
No problem! Please let me know if there is anything missing to help you build on your machine.
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.
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?
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?
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 ...
Can you please help to resolve this error? Thanks in advance!
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`)
Hi @Evangelink ,
Thanks got it. But how to run test for new rules in sonaranalyzer-dotnet?
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
Thank you for your help @Evangelink . I also appreciate your patience during the same.
@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 ...
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
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
I am trying to modify plugin and as per documentation i followed steps:
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: