diff --git a/AssemblyInfo.Shared.cs b/AssemblyInfo.Shared.cs index 75a846514..7df85fd65 100644 --- a/AssemblyInfo.Shared.cs +++ b/AssemblyInfo.Shared.cs @@ -21,9 +21,9 @@ using System.Reflection; using System.Runtime.InteropServices; -[assembly: AssemblyVersion("5.0.3")] -[assembly: AssemblyFileVersion("5.0.3.0")] -[assembly: AssemblyInformationalVersion("Version:5.0.3.0 Branch:not-set Sha1:not-set")] +[assembly: AssemblyVersion("5.0.4")] +[assembly: AssemblyFileVersion("5.0.4.0")] +[assembly: AssemblyInformationalVersion("Version:5.0.4.0 Branch:not-set Sha1:not-set")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("SonarSource and Microsoft")] [assembly: AssemblyCopyright("Copyright © SonarSource and Microsoft 2015-2020")] diff --git a/Tests/SonarScanner.MSBuild.TFS.Tests/Classic/BinaryToXmlCoverageReportConverterTests.cs b/Tests/SonarScanner.MSBuild.TFS.Tests/Classic/BinaryToXmlCoverageReportConverterTests.cs index 01ed6afea..528ddbb58 100644 --- a/Tests/SonarScanner.MSBuild.TFS.Tests/Classic/BinaryToXmlCoverageReportConverterTests.cs +++ b/Tests/SonarScanner.MSBuild.TFS.Tests/Classic/BinaryToXmlCoverageReportConverterTests.cs @@ -204,12 +204,14 @@ public void Initialize_CanGetGetExeToolPathFromSetupConfiguration() } [TestMethod] - public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable() + public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FullPathToCodeCoverageToolGiven() { // Arrange var logger = new TestLogger(); var config = new AnalysisConfig(); - config.SetVsCoverageConverterToolPath(@"My:\Path\To\CodeCoverage.exe"); + var filePath = Path.Combine(Environment.CurrentDirectory, "CodeCoverage.exe"); + File.Create(filePath); + config.SetVsCoverageConverterToolPath(filePath); var reporter = new BinaryToXmlCoverageReportConverter(logger, config); @@ -219,7 +221,52 @@ public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable() // Assert result.Should().BeTrue(); - logger.AssertDebugLogged(@"VsTestToolsInstallerInstalledToolLocation environment variable detected, taking this one as tool path for CodeCoverage.exe."); + logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}."); + } + + [TestMethod] + public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_NoExeInThePath_ShouldSeekForStandardInstall() + { + // Arrange + var logger = new TestLogger(); + var config = new AnalysisConfig(); + + var filePath = Path.Combine(Environment.CurrentDirectory, @"tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"); + Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + File.Create(filePath); + + config.SetVsCoverageConverterToolPath(Environment.CurrentDirectory); + + var reporter = new BinaryToXmlCoverageReportConverter(logger, config); + + // Act + var result = reporter.Initialize(); + + // Assert + result.Should().BeTrue(); + logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}."); + } + + [TestMethod] + public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FileDoesntExist_ShouldFallback() + { + // Arrange + var logger = new TestLogger(); + var config = new AnalysisConfig(); + var factory = CreateVisualStudioSetupConfigurationFactory("Microsoft.VisualStudio.TestTools.CodeCoverage"); + + config.SetVsCoverageConverterToolPath(Path.GetTempPath()); + + var reporter = new BinaryToXmlCoverageReportConverter(factory, logger, config); + + // Act + var result = reporter.Initialize(); + + // Assert + result.Should().BeTrue(); + + logger.Warnings.Contains("CodeCoverage.exe was not found in the standard locations. Please provide the full path of the tool using the VsTestToolsInstallerInstalledToolLocation variable."); + logger.AssertDebugLogged("Code coverage command line tool: x:\\foo\\Team Tools\\Dynamic Code Coverage Tools\\CodeCoverage.exe"); } [TestMethod] diff --git a/nuspec/netcoreglobaltool/dotnet-sonarscanner.nuspec b/nuspec/netcoreglobaltool/dotnet-sonarscanner.nuspec index 796f6c84e..4b0525d8a 100644 --- a/nuspec/netcoreglobaltool/dotnet-sonarscanner.nuspec +++ b/nuspec/netcoreglobaltool/dotnet-sonarscanner.nuspec @@ -2,7 +2,7 @@ dotnet-sonarscanner - 5.0.3 + 5.0.4 SonarScanner for .Net Core SonarSource,Microsoft http://redirect.sonarsource.com/doc/msbuild-sq-runner.html diff --git a/scripts/version/Version.props b/scripts/version/Version.props index b24ae8a70..62fae9bf0 100644 --- a/scripts/version/Version.props +++ b/scripts/version/Version.props @@ -1,6 +1,6 @@ - 5.0.3 + 5.0.4 0 not-set not-set diff --git a/src/SonarScanner.MSBuild.TFS.Classic/BinaryToXmlCoverageReportConverter.cs b/src/SonarScanner.MSBuild.TFS.Classic/BinaryToXmlCoverageReportConverter.cs index f90abc2ec..5507cfb69 100644 --- a/src/SonarScanner.MSBuild.TFS.Classic/BinaryToXmlCoverageReportConverter.cs +++ b/src/SonarScanner.MSBuild.TFS.Classic/BinaryToXmlCoverageReportConverter.cs @@ -49,6 +49,8 @@ public class BinaryToXmlCoverageReportConverter : ICoverageReportConverter /// private const string TeamToolPathandExeName = @"Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"; + private const string VsTestToolPlatformInstallerPathToExe = @"tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"; + /// /// Code coverage package names for Visual Studio setup configuration /// @@ -119,10 +121,26 @@ private string GetExeToolPath() this.logger.LogDebug(Resources.CONV_DIAG_LocatingCodeCoverageTool); var userSuppliedVsCoverageToolPath = this.config.GetVsCoverageConverterToolPath(); - if (userSuppliedVsCoverageToolPath != null) + if (!string.IsNullOrEmpty(userSuppliedVsCoverageToolPath)) { this.logger.LogDebug(Resources.CONV_DIAG_LocatingCodeCoverageToolUserSuppliedProperty); - return userSuppliedVsCoverageToolPath; + if (userSuppliedVsCoverageToolPath.EndsWith("CodeCoverage.exe") && File.Exists(userSuppliedVsCoverageToolPath)) + { + this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageFound, userSuppliedVsCoverageToolPath); + return userSuppliedVsCoverageToolPath; + } + + this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageIsNotInVariable); + var standardToolInstallerPath = Path.Combine(userSuppliedVsCoverageToolPath, VsTestToolPlatformInstallerPathToExe); + if (File.Exists(standardToolInstallerPath)) + { + this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageFound, standardToolInstallerPath); + return standardToolInstallerPath; + } + else + { + this.logger.LogWarning(Resources.CONV_WARN_UnableToFindCodeCoverageFileInUserSuppliedVariable); + } } return GetExeToolPathFromSetupConfiguration() diff --git a/src/SonarScanner.MSBuild.TFS.Classic/Resources.Designer.cs b/src/SonarScanner.MSBuild.TFS.Classic/Resources.Designer.cs index dc61dd8bc..452b18a69 100644 --- a/src/SonarScanner.MSBuild.TFS.Classic/Resources.Designer.cs +++ b/src/SonarScanner.MSBuild.TFS.Classic/Resources.Designer.cs @@ -60,6 +60,24 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to CodeCoverage.exe found at {0}.. + /// + internal static string CONV_DIAG_CodeCoverageFound { + get { + return ResourceManager.GetString("CONV_DIAG_CodeCoverageFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to VsTestToolsInstallerInstalledToolLocation environment variable doesn't contain full path to CodeCoverage.exe tool, seeking in standard place set by VSTestPlatformToolInstaller.... + /// + internal static string CONV_DIAG_CodeCoverageIsNotInVariable { + get { + return ResourceManager.GetString("CONV_DIAG_CodeCoverageIsNotInVariable", resourceCulture); + } + } + /// /// Looks up a localized string similar to Code coverage command line tool: {0}. /// @@ -97,7 +115,7 @@ internal static string CONV_DIAG_LocatingCodeCoverageToolSetupConfiguration { } /// - /// Looks up a localized string similar to VsTestToolsInstallerInstalledToolLocation environment variable detected, taking this one as tool path for CodeCoverage.exe.. + /// Looks up a localized string similar to VsTestToolsInstallerInstalledToolLocation environment variable detected, seeking for CodeCoverage.exe location.... /// internal static string CONV_DIAG_LocatingCodeCoverageToolUserSuppliedProperty { get { @@ -151,6 +169,15 @@ internal static string CONV_WARN_FailToFindConversionTool { } } + /// + /// Looks up a localized string similar to CodeCoverage.exe was not found in the standard locations. Please provide the full path of the tool using the VsTestToolsInstallerInstalledToolLocation variable.. + /// + internal static string CONV_WARN_UnableToFindCodeCoverageFileInUserSuppliedVariable { + get { + return ResourceManager.GetString("CONV_WARN_UnableToFindCodeCoverageFileInUserSuppliedVariable", resourceCulture); + } + } + /// /// Looks up a localized string similar to Connected to {0}. /// diff --git a/src/SonarScanner.MSBuild.TFS.Classic/Resources.resx b/src/SonarScanner.MSBuild.TFS.Classic/Resources.resx index 167f8ab04..1302a63e0 100644 --- a/src/SonarScanner.MSBuild.TFS.Classic/Resources.resx +++ b/src/SonarScanner.MSBuild.TFS.Classic/Resources.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + CodeCoverage.exe found at {0}. + + + VsTestToolsInstallerInstalledToolLocation environment variable doesn't contain full path to CodeCoverage.exe tool, seeking in standard place set by VSTestPlatformToolInstaller... + Code coverage command line tool: {0} @@ -130,7 +136,7 @@ Attempting to locate the CodeCoverage.exe tool using setup configuration... - VsTestToolsInstallerInstalledToolLocation environment variable detected, taking this one as tool path for CodeCoverage.exe. + VsTestToolsInstallerInstalledToolLocation environment variable detected, seeking for CodeCoverage.exe location... Multiple versions of VS are installed: {0} @@ -149,6 +155,9 @@ Check that the downloaded code coverage file ({0}) is valid by opening it in Vis Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage. + + CodeCoverage.exe was not found in the standard locations. Please provide the full path of the tool using the VsTestToolsInstallerInstalledToolLocation variable. + Connected to {0}