Skip to content
This repository was archived by the owner on Jul 14, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/CBT.NuGet/Internal/CBTBuildEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ public CBTBuildEngine()
//
BuildManager buildManager = BuildManager.DefaultBuildManager;

PropertyInfo loggingServiceProperty = buildManager.GetType().GetProperty("Microsoft.Build.BackEnd.IBuildComponentHost.LoggingService", BindingFlags.Instance | BindingFlags.NonPublic);
PropertyInfo loggingServiceProperty = buildManager?.GetType().GetProperty("Microsoft.Build.BackEnd.IBuildComponentHost.LoggingService", BindingFlags.Instance | BindingFlags.NonPublic);

if (loggingServiceProperty != null)
{
try
{
object loggingService = loggingServiceProperty.GetMethod.Invoke(buildManager, null);
object loggingService = null;

try
{
loggingService = loggingServiceProperty.GetMethod.Invoke(buildManager, null);
}
catch (TargetInvocationException e) when (e.InnerException is NullReferenceException)
{
// When a build is not taking place, there is no logging service. The LoggingService property attempts to cast which throws a NullReferenceException so this is ignored.
}

MethodInfo logBuildEventMethod = loggingService?.GetType().GetMethod("LogBuildEvent", new[] {typeof (BuildEventArgs)});

Expand Down