I am new to sonarQube & Resharper. And I used the Resharper to do the code analysis (Code developed in C# language) because without built the project we can do the code analysis by using the Resharper.
Now the Analysis running successfully (the resharper analysis)for the unittest project files not for the normal project file. If unittest project is missing in the sln file then the SonarQube throws an exception "No files to inspect were found." and the Analysis getting fails.
So my Question is how to run the code analysis(using Resharper in Sonar) to Normal project file sln file (with/without the unittest project in that sln file). Or commands to do the necessary changes in the Sonarqube input so that the Executing command will run the Resharper analysis to the all the project files.
Input to the SonarQube:
cd:\sonar-scanner-2.5\bin\sonar-runner.bat -e "-Dsonar.jdbc.url=jdbc:mysql://ip/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true" -Dsonar.host.url=http://ip/ "-Dsonar.projectBaseDir=cd:\workspace" -Dsonar.sourceEncoding=UTF-8 -Dsonar.sources=. -Dsonar.resharper.includeAllFiles=false -Dsonar.resharper.projectName=* -Dsonar.projectVersion=1.0 -Dsonar.projectKey=projectkey_cs "-Dsonar.resharper.solutionFile=cd:/workspace" -Dsonar.resharper.timeoutMinutes=30
-Dsonar.ndeps.mode=skip -Dsonar.gallio.mode=skip -Dsonar.projectName=projectName
Executing command: cd:/inspectcode.exe /output=cd:\resharper-report.xml /no-swea /project=* /profile=cd:.sonar\resharper-sonarqube.DotSettings /no-buildin-settings cd:\XXXX.sln
Related
I am using VS2017 Enterprise for first the time building my repository. Have cloned code from my VS repository and trying to build it but build failed.
And also i have set environment variable path -->
PATH : C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe
Error message :
Severity Code Description Project File Line Suppression State Error
MSBuild could not locate the Code Analysis tool at
'Drive:\Repo\NugetPackages\CarbonV2.FxCop.SDL.14.0.23107.0\Tools\FxCopCmd.exe'.
If MSBuild is being run from within the "Visual Studio Command
Prompt", specify the path to the Code Analysis tool by setting the
FXCOPDIR environment variable. Demo.Service.Common
Could you please help on this, did i missed any thing?
What's standing out to me is that i'm seeing NugetPackages - leading me to believe you're missing something from Nuget.
https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#restore-packages-automatically-using-visual-studio
You can install the FXCOP manually, or follow the instructions in that article to have NuGet attempt to get all of the missing packages automatically for you. Hope this helps!
I want to scan existing .cs files with sonarqube.
I understood that I need to use SonarQube Scanner for MSBuild, and this one requires to create a project to analyze. So I created a project on Visual studio from existing files and declared it as Class Library. But while executing SonarQube Scanner for MSBuild, I've got this error:
WARNING: The project has an invalid GUID "00000000-0000-0000-0000-
000000000000". The project will not be analyzed by SonarQube. Project
file: C:\Users\sas1\Documents\Visual Studio
2015\Projects\MSBuildTest\MSBuildTest.csproj
No analysable projects were found. SonarQube analysis will not be
performed. Check the build summary report for details.
Generation of the sonar-properties file failed. Unable to complete
SonarQube analysis.
09:54:16.866 Creating a summary markdown file...
09:54:16.872 Post-processing failed. Exit code: 1
I can not create a console application with those files, because thus I will have many compilation errors, which I am not supposed to correct, since the code is not mine, but just delegated to me.
So my question is: if someone gives me several .cs files to analyze using SonarQube, how can I analyse them using SonarQube Scanner for MSBuild?
Thank you
I have a project with classes and methods that I want to test. I have another project with the test methods that will test the methods of my main project.
I run the tests with opencover and I generate the reports with reportgenerator, with this commands that I have in a .bet file:
..\tools\OpenCover.Console.exe -register:user -target:"C:\myDllWithTests.dll" -output:"c:\coverage\opencovertests.xml"
.\ReportGenerator.exe "-reports:c:\coverage\opencovertests.xml" "-targetdir:c:\coverage\opencovertests.xml\reports"
I am using MSTest for testing.
The problem is that in the html report, I see that the code that is covered is the tests methods, not the methods in my test main project.
How I could add the main methods in the result?
Thanks.
In target argument for OpenCover pass the path to MSTest (e.g. "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe") and specify your test assemblies (e.g. "C:\myDllWithTests.dll") in targetargs argument.
To remove test assemblies from code coverage statistics, specify them in filter argument.
Below is OpenCover command that works fine for me. Here code under test is placed in SampleApp.dll and test code is placed in SampleApp.Tests.dll.
.\OpenCover.Console.exe -register:user -mergebyhash -target:"c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" -targetargs:"/testcontainer:\"d:\test\SampleApp\SampleApp.Tests\bin\Debug\SampleApp.Tests.dll\"" -output:UTResults.xml -filter:"+[SampleApp*]* -[SampleApp.Tests]*"
Result report contains only stats for SampleApp.dll assembly, SampleApp.Tests.dll is excluded:
Check this answer for some more details.
There is also a great article by Allen Conway on using OpenCover & ReportGenerator for .Net projects.
This might be quite a late answer here, but I've spent an hour or two playing with this and found the following will fix this. It's worth noting that I had the original bat script from another project that I know works, and just changed the DLL file name, so I know the script was OK.
The additional check to make is to:-
Right click the project that has the source code you want visible in the coverage report (not the unit test project) and click Properties
Select Build > Output > Advanced
Set Debugging information to Full
Rebuild solution and re-run bat file.
Works for me in Visual Studio 2019 with .NET Framework 4.7.2 projects.
By default, code analysis is only done for projects which are compiled. So when I run MSBuild from the command line, it runs code analysis only for the first time. On subsequent calls, code analysis is skipped.
Background: I want to evaluate CA rules and see how many warnings there would be in our code when turning on a rule. For that I don't want to recompile everything - which takes some time - but just re-run the code analysis. How can you achieve this?
I am using Visual Studio 2013 and MSBuild 12.0.
Even explicitely switching on code analysis does not help:
msbuild DesktopBuild.proj /p:RunCodeAnalysis=true
It seems that
del /s *.lastcodeanalysissucceeded
msbuild DesktopBuild.proj /p:RunCodeAnalysis=true
seems to work. The first step causes code analysis to "forget" about the previous runs and the second step forces it to run for every project, even if code analysis is not enabled in a project. If running this repeatedly, the already compiled projects won't be compiled again, only the code analysis is re-run.
Simply set CodeAnalysisGenerateSuccessFile to false in the project file.
<PropertyGroup>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisGenerateSuccessFile>false</CodeAnalysisGenerateSuccessFile>
</PropertyGroup>
I would try using FxCopCmd.exe, it can be usually found in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop. It's used by CodeAnalysis in Visual Studio, you should be able to use it with proper parameters.
I have downloaded Apache Thrift 0.9.1 from here: http://wiki.apache.org/thrift/ThriftUsageCSharp. In Visual Studio 2010, I opened the .sln file in thrift/lib/csharp/src.
However, I am unable to build the solution. I'm getting this error:
Error 3 The command "rmdir /s /q "C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\gen-csharp"
del /f /q "C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\ThriftImpl.dll"
SET OUTPUT_DIR=C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\
SET THRIFT_FILE=C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\\..\..\..\..\test\ThriftTest.thrift
for %%I in ("%OUTPUT_DIR%") do set SHORT_DIR=%%~fsI
for %%I in ("%THRIFT_FILE%") do set THRIFT_SHORT=%%~fs
"C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\\..\..\..\..\compiler\cpp\thrift.exe" --gen csharp -o %SHORT_DIR% %THRIFT_SHORT%
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /t:library /out:"C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\ThriftImpl.dll" /recurse:"C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\gen-csharp"\* /reference:"C:\Users\RS88517\Documents\Visual Studio 2010\Projects\thrift-0.9.1\lib\csharp\test\ThriftTest\..\..\src\bin\Debug\Thrift.dll"" exited with code 1.
I've looked in a number of places and am not sure what to do.
That's the pre-build step of the ThriftTest project. If you have troubles with it, which can be difficult to debug, proceed as follows:
Remove the prebuild step stuff entirely from the C# project (Project Properties dialog, Build Events tab)
Compile the \lib\csharp\src\Thrift.csproj to produce the Thrift runtime assembly. Alternatively, consider including the Thrift.csproj project into the solution, which makes it easier to handle.
Open a command line, navigate to the appropriate folder and call thrift.exe --gen csharp ThriftTest.thrift to generate the code from the IDL. This will produce a new folder gen-csharp with a bunch of files in it. The ThriftTest.thrift IDL file is located in the \test folder.
Make sure the generated files from step 3 are included in the ThriftTest project
Build everything
Note that for step 3 you need the Thrift compiler (thrift.exe) in your path. This file is available as precompiled download on the Apache Thrift web site, you don't need to build it on your own.