Skip to content

Commit

Permalink
Fixed problem when project and assembly name doesnt match (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
MilleBo authored Feb 13, 2020
1 parent b521a37 commit 8baf378
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Testura.Mutation.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
26 changes: 25 additions & 1 deletion src/Testura.Mutation.Core/Extensions/AnalyzerResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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<string>();
foreach (Match match in Regex.Matches(fileContent, "<AssemblyName>(.*?)</AssemblyName>"))
{
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 8baf378

Please sign in to comment.