Skip to content

Commit

Permalink
This is version 0.1.1.
Browse files Browse the repository at this point in the history
Fix the initialization of the MSBuildWeaver.Log2 field.
Mark only MSBuildWeaver.AssemblyPath as required.
  • Loading branch information
teo-tsirpanis committed Apr 8, 2020
1 parent d89024e commit 21a82f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
32 changes: 22 additions & 10 deletions Sigourney/MSBuildWeaver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using JetBrains.Annotations;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Expand All @@ -17,13 +18,14 @@ namespace Sigourney
// ReSharper disable once InconsistentNaming
public abstract class MSBuildWeaver : Task
{
[Required] public bool SignAssembly { get; set; }
private ILogger _log2;
public bool SignAssembly { get; set; }

public string? IntermediateDirectory { get; set; }

[Required] public string? KeyOriginatorFile { get; set; }
public string? KeyOriginatorFile { get; set; }

[Required] public string? AssemblyOriginatorKeyFile { get; set; }
public string? AssemblyOriginatorKeyFile { get; set; }

/// <summary>
/// The path of the assembly to weave.
Expand All @@ -43,8 +45,22 @@ public abstract class MSBuildWeaver : Task
/// A Serilog <see cref="ILogger"/> that redirects events to MSBuild.
/// </summary>
/// <remarks>The type was named <c>Log2</c> to distinguish itself from
/// the less flexible MSBuild's <see cref="Log"/> property.</remarks>
protected ILogger Log2 = Logger.None;
/// the less flexible <see cref="Log"/> property.</remarks>
public ILogger Log2
{
get
{
if (_log2 != null) return _log2;
var log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.MSBuild(this)
.CreateLogger()
.ForContext(MSBuildProperties.File, AssemblyPath);
Interlocked.Exchange(ref _log2, log);

return _log2;
}
}

/// <summary>
/// Performs the actual weaving of the assembly.
Expand All @@ -61,11 +77,6 @@ public abstract class MSBuildWeaver : Task
/// <inheritdoc/>
public override bool Execute()
{
Log2 = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.MSBuild(this)
.CreateLogger()
.ForContext(MSBuildProperties.File, AssemblyPath);
try
{
if (string.IsNullOrEmpty(IntermediateDirectory))
Expand All @@ -74,6 +85,7 @@ public override bool Execute()
" Please set it to '$(ProjectDir)$(IntermediateOutputPath)'.");
return false;
}

var config = new WeaverConfig
{
KeyFilePath = KeyOriginatorFile ?? AssemblyOriginatorKeyFile,
Expand Down
4 changes: 2 additions & 2 deletions Sigourney/Sigourney.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<PackageId>Sigourney</PackageId>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<Version>0.1.0</Version>
<PackageReleaseNotes>Fix a couple of bugs. Refactor the API once again.</PackageReleaseNotes>
<Version>0.1.1</Version>
<PackageReleaseNotes>MSBuildWeaver.Log2 is properly initialized. Only MSBuildWeaver.AssemblyPath is marked as required.</PackageReleaseNotes>
<Authors>Theodore Tsirpanis</Authors>
<Copyright>Copyright © Theodore Tsirpanis. Licensed under the MIT License. Contains some code from Fody, which is licensed under the MIT License as well.</Copyright>
<PackageProjectUrl>https://github.com/teo-tsirpanis/Sigourney</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Sigourney/StrongNameKeyFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal static class StrongNameKeyFinder
private static string? GetKeyFilePath(WeaverConfig config, AssemblyDefinition asm, ILogger log)
{
var keyFilePath = config.KeyFilePath;
if (keyFilePath != null)
if (!string.IsNullOrEmpty(config.KeyFilePath))
{
keyFilePath = Path.GetFullPath(keyFilePath);
log.Debug("Using strong name key from KeyFilePath '{KeyFilePath}'.", keyFilePath);
Expand Down

0 comments on commit 21a82f3

Please sign in to comment.