SONARQUBE错误地将我的源代码分析为测试代码

时间:2016-10-17 16:26:17

标签: c# msbuild sonarqube sonarqube-msbuild-runner

我在Sonarqube 6中有两个项目,其中一个项目按预期运行。另一个是分析,但是将它发现的代码分类为测试代码。

请参阅日志中的以下摘录:

2016-10-17T15:30:45.9139431Z INFO: -------------  Scan XXXX.WebApp.Advisor.CrossCuttings.Constants
2016-10-17T15:30:45.9139431Z INFO: Excluded sources for coverage:
2016-10-17T15:30:45.9139431Z INFO:   **/I*.cs
2016-10-17T15:30:45.9139431Z INFO:   **/*DTO.cs
2016-10-17T15:30:45.9139431Z INFO:   **/*ViewModel.cs
2016-10-17T15:30:45.9139431Z INFO:   **/AssemblyInfo.cs
2016-10-17T15:30:45.9139431Z INFO:   **/project.json
2016-10-17T15:30:45.9139431Z INFO: Base dir: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.CrossCuttings.Constants
2016-10-17T15:30:45.9139431Z INFO: Working dir: C:\agent\_work\12\.sonarqube\out\.sonar\DigitalDelivery-AdvisorPortal_DigitalDelivery-AdvisorPortal_9E577C4E-1343-4FC4-BC51-CA75DE04C8C7
2016-10-17T15:30:45.9139431Z INFO: Test paths: Parameter.cs, Properties/AssemblyInfo.cs, packages.config
2016-10-17T15:30:45.9139431Z INFO: Source encoding: UTF-8, default locale: en_US
2016-10-17T15:30:45.9139431Z INFO: Index files
2016-10-17T15:30:45.9139431Z INFO: Excluded sources:
2016-10-17T15:30:45.9139431Z INFO:   **/Scripts/Global/**/*.*
2016-10-17T15:30:45.9139431Z INFO: 2 files indexed
2016-10-17T15:30:45.9139431Z INFO: 0 files ignored because of inclusion/exclusion patterns
2016-10-17T15:30:45.9139431Z INFO: Quality profile for cs: Sonar way
2016-10-17T15:30:45.9139431Z INFO: Sensor Lines Sensor
2016-10-17T15:30:45.9305374Z INFO: Sensor Lines Sensor (done) | time=0ms
2016-10-17T15:30:45.9305374Z INFO: Sensor Sonar-Sonargraph-Plugin [3.5]
2016-10-17T15:30:45.9305374Z INFO: ----------------------------------------------------------------
2016-10-17T15:30:45.9305374Z INFO: Sonargraph: Skipping project XXXX.WebApp.Advisor.CrossCuttings.Constants [DigitalDelivery-AdvisorPortal:DigitalDelivery-AdvisorPortal:9E577C4E-1343-4FC4-BC51-CA75DE04C8C7], since no Sonargraph rules are activated in current SonarQube quality profile.
2016-10-17T15:30:45.9305374Z INFO: ----------------------------------------------------------------
2016-10-17T15:30:45.9305374Z INFO: Sensor Sonar-Sonargraph-Plugin [3.5] (done) | time=0ms
2016-10-17T15:30:45.9305374Z INFO: Sensor org.sonar.plugins.csharp.CSharpCodeCoverageProvider$CSharpCoverageReportImportSensor
2016-10-17T15:30:45.9305374Z INFO: Parsing the Visual Studio coverage XML report C:\agent\_work\12\TestResults\LOCAL SERVICE_BUILDBOX1 2016-10-17 16_30_21\In\BUILDBOX1\LOCAL SERVICE_BUILDBOX1 2016-10-17 16_30_06.coveragexml
2016-10-17T15:30:45.9305374Z INFO: Adding this code coverage report to the cache for later reuse: C:\agent\_work\12\TestResults\LOCAL SERVICE_BUILDBOX1 2016-10-17 16_30_21\In\BUILDBOX1\LOCAL SERVICE_BUILDBOX1 2016-10-17 16_30_06.coveragexml
2016-10-17T15:30:45.9305374Z INFO: Sensor org.sonar.plugins.csharp.CSharpCodeCoverageProvider$CSharpCoverageReportImportSensor (done) | time=62ms
2016-10-17T15:30:45.9305374Z INFO: Sensor SCM Sensor
2016-10-17T15:30:45.9305374Z INFO: No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
2016-10-17T15:30:45.9305374Z INFO: Sensor SCM Sensor (done) | time=0ms
2016-10-17T15:30:45.9305374Z INFO: Sensor XmlFileSensor
2016-10-17T15:30:45.9305374Z INFO: Sensor XmlFileSensor (done) | time=0ms
2016-10-17T15:30:45.9305374Z INFO: Sensor Zero Coverage Sensor
2016-10-17T15:30:45.9305374Z INFO: Sensor Zero Coverage Sensor (done) | time=0ms
2016-10-17T15:30:45.9305374Z INFO: Sensor Code Colorizer Sensor
2016-10-17T15:30:45.9305374Z INFO: Sensor Code Colorizer Sensor (done) | time=0ms
2016-10-17T15:30:45.9305374Z INFO: Sensor CPD Block Indexer
2016-10-17T15:30:45.9305374Z INFO: DefaultCpdBlockIndexer is used for cs
2016-10-17T15:30:45.9305374Z INFO: Copy-paste detection exclusions:
2016-10-17T15:30:45.9305374Z **/stylecop.json
2016-10-17T15:30:45.9305374Z INFO: Sensor CPD Block Indexer (done) | time=0ms

参见以下部分:

2016-10-17T15:30:45.9139431Z INFO: Test paths: Parameter.cs, Properties/AssemblyInfo.cs, packages.config

此C#项目中的代码已标记为测试代码,因此尚未进行分析。什么控制了这个?如何扭转行为?

我觉得奇怪的是,解决方案中的一个项目得到了正确分析:

2016-10-17T15:30:46.1326703Z INFO: -------------  Scan XXXX.WebApp.Advisor.Presentation.MVC5
2016-10-17T15:30:46.1326703Z INFO: Excluded sources for coverage:
2016-10-17T15:30:46.1326703Z INFO:   **/I*.cs
2016-10-17T15:30:46.1326703Z INFO:   **/*DTO.cs
2016-10-17T15:30:46.1326703Z INFO:   **/*ViewModel.cs
2016-10-17T15:30:46.1326703Z INFO:   **/AssemblyInfo.cs
2016-10-17T15:30:46.1326703Z INFO:   **/project.json
2016-10-17T15:30:46.1326703Z INFO: Base dir: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5
2016-10-17T15:30:46.1326703Z INFO: Working dir: C:\agent\_work\12\.sonarqube\out\.sonar\DigitalDelivery-AdvisorPortal_DigitalDelivery-AdvisorPortal_C7028C31-65FE-4DFA-B557-6BC43CBA0B0D
2016-10-17T15:30:46.1326703Z INFO: Source paths: App_Start/BundleConfig.cs, App_Start/DependencyConfig.cs, App_Start/FilterConfig.cs, App_Start/IdentityConfig.cs, App_Start/RouteConfig.cs, App_Start/Startup.Auth.cs, BootStrapper.cs, Common/DistributorContainer.cs, Common/ExceptionHandler.cs, Common/RuleLookup.cs, Constants/PortalConstants.cs, Controllers/AccountController.cs, Controllers/ApplicationController.cs, Controllers/HomeController.cs, Controllers/ManageController.cs, Controllers/ClientDetailsController.cs, Controllers/QuotationController.cs, Controllers/UnderWritingController.cs, Extensions/CustomValidatorExtension.cs, Extensions/HtmlHelper.cs, Extensions/SessionExtension.cs, Extensions/WebViewExtension.cs, Filters/DistributorFilterAttribute.cs, Global.asax.cs, Models/AccountViewModels.cs, Models/Binder/DateTimeBinder.cs, Models/IdentityModels.cs, Models/ManageViewModels.cs, Properties/AssemblyInfo.cs, Startup.cs, Validators/BenefitParaSubmitViewModelValidator.cs, Validators/ClientViewModelValidator.cs, Validators/CustomValidator/ValidateDate.cs, Validators/ProductBenefitViewModelValidator.cs, Validators/QuotationClientViewModelValidator.cs, Validators/ValidatorFactory.cs, App_Data/RuleLookups.xml, Content/Application/Applications.css, Content/Customer/Customers.css, Content/Distributors/staysure/en-US/css/layout.css, Content/Distributors/staysure/images/DD_Gaurantee.png, Content/Distributors/staysure/images/logo.png, Content/Distributors/staysure/images/logo2.jpg, Content/Distributors/uib/en-US/css/layout.css, Content/Distributors/uib/images/DD_Gaurantee.png, Content/Distributors/uib/images/logo.png, Content/Global/Css/bootstrap/bootstrap-datepicker.css, Content/Global/Css/bootstrap/bootstrap-rtl.css, Content/Global/Css/bootstrap/bootstrap.css, Content/Global/Css/bootstrap/bootstrap.min.css, Content/Global/Css/bootstrap/font-awesome.css, Content/Global/Css/branding.css, Content/Global/Css/datatables/jquery.dataTables.css, Content/Global/Css/fonts/fontawesome-webfont.svg, Content/Global/Css/fonts/iconfont.css, Content/Global/Css/fonts/Metrize-Icons.dev.svg, Content/Global/Css/fonts/Metrize-Icons.svg, Content/Global/Css/google/font-family-droid-sans.css, Content/Global/Css/google/font-family-source-sans-pro.css, Content/Global/Css/iconfont.css, Content/Global/Css/Site.css, Content/Global/Css/style.css, Content/Global/Css/styleguide.css, Content/Global/fonts/glyphicons-halflings-regular.svg, Content/Global/images/arrow-up.jpg, Content/Global/images/arrow-up.png, Content/Global/images/bg/bottom-footer-gradient.jpg, Content/Global/images/bg/green-gradient.gif, Content/Global/images/bg/green-hover.gif, Content/Global/images/bg/header-gradient.jpg, Content/Global/images/bg/nav-gradient.jpg, Content/Global/images/bg/orange-gradient.gif, Content/Global/images/bg/top-footer-gradient.jpg, Content/Global/images/close.png, Content/Global/images/list-icon.png, Content/Global/images/list-ltr.png, Content/Global/images/loader.gif, Content/Global/images/logo.png, Content/Global/images/pdf.png, Content/Global/images/plus.png, Content/Global/images/sort_asc.png, Content/Global/images/sort_both.png, Content/Global/images/sort_desc.png, Content/Global/images/status.gif, Content/Global/images/tables/minus.png, Content/Global/images/tables/plus.png, Content/Global/images/tabs-grad.jpg, Content/Global/images/tabs-passed.jpg, Content/Home/Css/dashboard.css, Content/Quotation/Quotations.css, Content/Quotation/step.css, favicon.ico, fonts/glyphicons-halflings-regular.svg, Global.asax, Scripts/Customer/Customers.js, Scripts/Application/Applications.js, Scripts/Global/jquery.dataTables.js, Scripts/Quotation/AcceptPricingTerms.js, Scripts/Global/bootstrap.js, Scripts/Global/bootstrap.min.js, Content/Global/fonts/glyphicons-halflings-regular.eot, Content/Global/fonts/glyphicons-halflings-regular.ttf, Content/Global/fonts/glyphicons-halflings-regular.woff, Content/Global/Css/fonts/fontawesome-webfont.eot, Content/Global/Css/fonts/fontawesome-webfont.ttf, Content/Global/Css/fonts/fontawesome-webfont.woff, Content/Global/Css/fonts/FontAwesome.otf, Content/Global/Css/fonts/Metrize-Icons.eot, Content/Global/Css/fonts/Metrize-Icons.ttf, Content/Global/Css/fonts/Metrize-Icons.woff, Scripts/Global/footable.js, Scripts/Global/gauge/justgage.js, Scripts/Global/gauge/raphael.2.1.0.min.js, Scripts/Global/globalize.culture.en-US.js, Scripts/Global/globalize.culture.zh-CN.js, Scripts/Global/globalize.js, Scripts/Global/jquery-1.10.2.js, Scripts/Global/jquery-1.10.2.min.js, Scripts/Global/jquery.hcsticky.js, Scripts/Global/jquery.metadata.js, Scripts/Global/jquery.validate.js, Scripts/Global/jquery.validate.min.js, Scripts/Global/jquery.validate.unobtrusive.js, Scripts/Global/jquery.validate.unobtrusive.min.js, Scripts/Global/jquery.wizard.js, Scripts/Global/modernizr-2.6.2.js, Scripts/Global/respond.js, Scripts/Global/respond.min.js, Scripts/Home/dashboard.js, Scripts/Quotation/AcceptQuote.js, Scripts/Quotation/ClientDetails.js, Scripts/Quotation/BillingDetail.js, Scripts/Quotation/ConfirmationAndBuy.js, Scripts/Quotation/ContractAndPrice.js, Scripts/Quotation/DeclineOrRefer.js, Scripts/Quotation/FullMedicalReview.js, Scripts/Quotation/MedicalReview.js, Scripts/Quotation/ProductAndBenefit.js, Scripts/Quotation/Quotation.js, Scripts/Home/header.js, Scripts/Quotation/Quotations.js, Scripts/Quotation/SecondClientDetails.js, Scripts/Quotation/TermsAndConditions.js, Scripts/_references.js, StartUp.html, Web.config, Web.Debug.config, Web.Release.config, Views/Web.config, Views/_ViewStart.cshtml, Views/Shared/Error.cshtml, Views/Shared/_Layout.cshtml, Views/Home/About.cshtml, Views/Home/Contact.cshtml, Views/Home/Index.cshtml, Views/Account/_ExternalLoginsListPartial.cshtml, Views/Account/ConfirmEmail.cshtml, Views/Account/ExternalLoginConfirmation.cshtml, Views/Account/ExternalLoginFailure.cshtml, Views/Account/ForgotPassword.cshtml, Views/Account/ForgotPasswordConfirmation.cshtml, Views/Account/Login.cshtml, Views/Account/Register.cshtml, Views/Account/ResetPassword.cshtml, Views/Account/ResetPasswordConfirmation.cshtml, Views/Account/SendCode.cshtml, Views/Account/VerifyCode.cshtml, Views/Manage/AddPhoneNumber.cshtml, Views/Manage/ChangePassword.cshtml, Views/Manage/Index.cshtml, Views/Manage/ManageLogins.cshtml, Views/Manage/SetPassword.cshtml, Views/Manage/VerifyPhoneNumber.cshtml, Views/Shared/Lockout.cshtml, Views/Shared/_LoginPartial.cshtml, Views/Shared/_Header.cshtml, Views/Shared/_Footer.cshtml, Views/Home/Dashboard.cshtml, Views/Quotation/NewClientDetails.cshtml, Views/Quotation/NewQuotation.cshtml, Views/Quotation/ProductAndBenefit.cshtml, Views/Quotation/ContractAndPricing.cshtml, Views/Quotation/AcceptQuote.cshtml, Views/Quotation/TermsAndConditions.cshtml, Views/Quotation/QuotationBillDetail.cshtml, Views/Quotation/DeclineOrRefer.cshtml, Views/Quotation/ConfirmationAndBuy.cshtml, Views/UnderWriting/FullMedicalReview.cshtml, Views/UnderWriting/MedicalReview.cshtml, Views/Shared/_ErrorMessage.cshtml, Views/Quotation/AcceptPricingTerms.cshtml, Views/Customer/Customers.cshtml, Views/Quotation/Quotations.cshtml, Views/Application/Applications.cshtml, Views/Quotation/ContractIssue.cshtml, Views/Quotation/SecondClientDetails.cshtml, Views/Shared/_Loading.cshtml, fonts/glyphicons-halflings-regular.woff, fonts/glyphicons-halflings-regular.ttf, fonts/glyphicons-halflings-regular.eot, packages.config, Scripts/Global/jquery-1.10.2.min.map, Properties/PublishProfiles/AutomatedDeployment.pubxml, Properties/PublishProfiles/AutomatedDeploymentFileSystem.pubxml, Scripts/Global/jquery-1.10.2.intellisense.js, Scripts/Global/jquery.validate-vsdoc.js, Project_Readme.html
2016-10-17T15:30:46.1326703Z INFO: Source encoding: UTF-8, default locale: en_US
2016-10-17T15:30:46.1326703Z INFO: Index files
2016-10-17T15:30:46.1326703Z INFO: Excluded sources:
2016-10-17T15:30:46.1326703Z INFO:   **/Scripts/Global/**/*.*
2016-10-17T15:30:46.1326703Z INFO: 58 files indexed
2016-10-17T15:30:46.1326703Z INFO: 24 files ignored because of inclusion/exclusion patterns
2016-10-17T15:30:46.1326703Z INFO: Quality profile for cs: Sonar way
2016-10-17T15:30:46.1326703Z INFO: Quality profile for js: Sonar way
2016-10-17T15:30:46.1326703Z INFO: Quality profile for web: Sonar way
2016-10-17T15:30:46.1326703Z INFO: Quality profile for xml: Sonar way
2016-10-17T15:30:46.1326703Z INFO: All FxCop rules are disabled, skipping its execution.
2016-10-17T15:30:46.1326703Z INFO: Sensor Lines Sensor
2016-10-17T15:30:46.1326703Z INFO: Sensor Lines Sensor (done) | time=15ms
2016-10-17T15:30:46.1326703Z INFO: Sensor Sonar-Sonargraph-Plugin [3.5]
2016-10-17T15:30:46.1326703Z INFO: ----------------------------------------------------------------
2016-10-17T15:30:46.1326703Z INFO: Sonargraph: Skipping project XXXX.WebApp.Advisor.Presentation.MVC5 [DigitalDelivery-AdvisorPortal:DigitalDelivery-AdvisorPortal:C7028C31-65FE-4DFA-B557-6BC43CBA0B0D], since no Sonargraph rules are activated in current SonarQube quality profile.
2016-10-17T15:30:46.1326703Z INFO: ----------------------------------------------------------------
2016-10-17T15:30:46.1326703Z INFO: Sensor Sonar-Sonargraph-Plugin [3.5] (done) | time=0ms
2016-10-17T15:30:46.1326703Z INFO: Sensor org.sonar.plugins.csharp.CSharpSensor
2016-10-17T15:30:46.1326703Z INFO: SonarLint for Visual Studio version 1.13.0.0
2016-10-17T15:30:46.2576727Z INFO: 0/36 files analyzed, starting to analyze: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5\App_Start\BundleConfig.cs
2016-10-17T15:30:47.2420820Z INFO: 1/36 files analyzed, starting to analyze: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5\App_Start\DependencyConfig.cs
2016-10-17T15:30:47.2420820Z INFO: 2/36 files analyzed, starting to analyze: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5\App_Start\FilterConfig.cs
2016-10-17T15:30:47.2420820Z INFO: 3/36 files analyzed, starting to analyze: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5\App_Start\IdentityConfig.cs
2016-10-17T15:30:47.2420820Z INFO: 4/36 files analyzed, starting to analyze: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5\App_Start\RouteConfig.cs
2016-10-17T15:30:47.2420820Z INFO: 5/36 files analyzed, starting to analyze: C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5\App_Start\Startup.Auth.cs

...

我认为它可能是项目级别设置,因此我删除了原始SQ项目并创建了一个新项目。这没有任何区别。我试过添加

<Property Name="sonar.test.inclusions">file:**/*XXXX.WebApp*Test*/**/*.*</Property>

但这没有任何区别。

所以我现在不知道发生了什么。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:0)

所以我越来越接近我觉得,sonar-project.properties文件看起来不正确。当我使用VSTS任务时,我需要调查它正在做什么。

BF14297E-4A17-4869-9612-E3CBB92E573B.sonar.stylecop.projectFilePath=C:\\agent\\_work\\12\\s\\Seeds\\XXXX.WebApp.Advisor\\solution\\src\\XXXX.WebApp.Advisor.CrossCuttings.Configuration\\XXXX.WebApp.Advisor.CrossCuttings.Configuration.csproj

9E577C4E-1343-4FC4-BC51-CA75DE04C8C7.sonar.projectKey=DigitalDelivery-AdvisorPortal6:9E577C4E-1343-4FC4-BC51-CA75DE04C8C7
9E577C4E-1343-4FC4-BC51-CA75DE04C8C7.sonar.projectName=XXXX.WebApp.Advisor.CrossCuttings.Constants
9E577C4E-1343-4FC4-BC51-CA75DE04C8C7.sonar.projectBaseDir=C:\\agent\\_work\\12\\s\\Seeds\\XXXX.WebApp.Advisor\\solution\\src\\XXXX.WebApp.Advisor.CrossCuttings.Constants
9E577C4E-1343-4FC4-BC51-CA75DE04C8C7.sonar.cs.vscoveragexml.reportsPaths=C:\\agent\\_work\\12\\TestResults\\LOCAL SERVICE_BUILDBOX1 2016-10-19 08_54_30\\In\\BUILDBOX1\\LOCAL SERVICE_BUILDBOX1 2016-10-19 08_54_15.coveragexml
9E577C4E-1343-4FC4-BC51-CA75DE04C8C7.sonar.sources=
9E577C4E-1343-4FC4-BC51-CA75DE04C8C7.sonar.tests=\
C:\\agent\\_work\\12\\s\\Seeds\\XXXX.WebApp.Advisor\\solution\\src\\XXXX.WebApp.Advisor.CrossCuttings.Constants\\Parameter.cs,\
C:\\agent\\_work\\12\\s\\Seeds\\XXXX.WebApp.Advisor\\solution\\src\\XXXX.WebApp.Advisor.CrossCuttings.Constants\\Properties\\AssemblyInfo.cs,\
C:\\agent\\_work\\12\\s\\Seeds\\XXXX.WebApp.Advisor\\solution\\src\\XXXX.WebApp.Advisor.CrossCuttings.Constants\\packages.config

答案 1 :(得分:0)

另外一个文件进一步强调了这个问题。文件'ProjectInfo.log'

Product projects
---------------------------------------
C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.Presentation.MVC5\XXXX.WebApp.Advisor.Presentation.MVC5.csproj


Test projects
---------------------------------------
C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.CrossCuttings.Configuration\XXXX.WebApp.Advisor.CrossCuttings.Configuration.csproj
C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.CrossCuttings.Constants\XXXX.WebApp.Advisor.CrossCuttings.Constants.csproj
C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\test\XXXX.WebApp.Advisor.CrossCuttings.Logging.UTest\XXXX.WebApp.Advisor.CrossCuttings.Logging.UTest.csproj
C:\agent\_work\12\s\Seeds\XXXX.WebApp.Advisor\solution\src\XXXX.WebApp.Advisor.CrossCuttings.Logging\XXXX.WebApp.Advisor.CrossCuttings.Logging.csproj