From 8baf378c126f94e32a310edf13a7d0a64ef8ed16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mille=20Bostr=C3=B6m?= Date: Thu, 13 Feb 2020 08:35:35 +0100 Subject: [PATCH] Fixed problem when project and assembly name doesnt match (#32) --- .../Properties/AssemblyInfo.cs | 4 +-- .../Extensions/AnalyzerResultExtensions.cs | 26 ++++++++++++++++++- .../Solution/MsBuildSolutionOpener.cs | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Testura.Mutation.Console/Properties/AssemblyInfo.cs b/src/Testura.Mutation.Console/Properties/AssemblyInfo.cs index 8f9241a..b61b35c 100644 --- a/src/Testura.Mutation.Console/Properties/AssemblyInfo.cs +++ b/src/Testura.Mutation.Console/Properties/AssemblyInfo.cs @@ -32,7 +32,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.1.0")] -[assembly: AssemblyFileVersion("1.4.1.0")] +[assembly: AssemblyVersion("1.4.2.0")] +[assembly: AssemblyFileVersion("1.4.2.0")] [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4Net.config", Watch = true)] [assembly: LogMinimalMessage] diff --git a/src/Testura.Mutation.Core/Extensions/AnalyzerResultExtensions.cs b/src/Testura.Mutation.Core/Extensions/AnalyzerResultExtensions.cs index 62e04df..4538097 100644 --- a/src/Testura.Mutation.Core/Extensions/AnalyzerResultExtensions.cs +++ b/src/Testura.Mutation.Core/Extensions/AnalyzerResultExtensions.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using Buildalyzer; using Buildalyzer.Workspaces; using Microsoft.CodeAnalysis; @@ -111,12 +112,14 @@ public static Project AddToWorkspace(this AnalyzerResult analyzerResult, Workspa private static ProjectInfo GetProjectInfo(AnalyzerResult analyzerResult, Workspace workspace, ProjectId projectId) { var projectName = Path.GetFileNameWithoutExtension(analyzerResult.ProjectFilePath); + var assemblyName = GetAssemblyName(analyzerResult.ProjectFilePath); + var languageName = GetLanguageName(analyzerResult.ProjectFilePath); var projectInfo = ProjectInfo.Create( projectId, VersionStamp.Create(), projectName, - projectName, + assemblyName, languageName, filePath: analyzerResult.ProjectFilePath, outputFilePath: analyzerResult.GetProperty("TargetPath"), @@ -308,5 +311,26 @@ private static Encoding GetEncoding(string filename) } } } + + private static string GetAssemblyName(string projectPath) + { + try + { + var fileContent = File.ReadAllText(projectPath); + + var items = new List(); + foreach (Match match in Regex.Matches(fileContent, "(.*?)")) + { + items.Add(match.Groups[1].Value); + } + + var name = string.Join(" ", items); + return !string.IsNullOrEmpty(name) ? name : Path.GetFileNameWithoutExtension(projectPath); + } + catch (Exception) + { + return Path.GetFileNameWithoutExtension(projectPath); + } + } } } diff --git a/src/Testura.Mutation.Core/Solution/MsBuildSolutionOpener.cs b/src/Testura.Mutation.Core/Solution/MsBuildSolutionOpener.cs index 0e9cb96..1e88e01 100644 --- a/src/Testura.Mutation.Core/Solution/MsBuildSolutionOpener.cs +++ b/src/Testura.Mutation.Core/Solution/MsBuildSolutionOpener.cs @@ -29,6 +29,7 @@ public class MsBuildSolutionOpener : ISolutionOpener LogTo.Info($"Building {Path.GetFileNameWithoutExtension(projectKeyValue.Key)}"); var project = projectKeyValue.Value; var results = project.Build(environmentOptions); + if (!results.OverallSuccess) { LogTo.Error("Failed to build");