Skip to content

Commit

Permalink
Make Unregister a no-op Fixes #77 (#204)
Browse files Browse the repository at this point in the history
* Make Unregister a no-op

* Change comment

* Specify not to show Unregister

* Sort usings

---------

Co-authored-by: Forgind <[email protected]>
  • Loading branch information
Forgind and Forgind authored Aug 4, 2023
1 parent 5a83d52 commit 7f1d5a5
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/MSBuildLocator/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -283,26 +284,11 @@ Assembly TryLoadAssembly(AssemblyName assemblyName)
}

/// <summary>
/// Remove assembly resolution previously registered via <see cref="RegisterInstance" />, <see cref="RegisterMSBuildPath" />, or <see cref="RegisterDefaults" />.
/// This has no effect and exists only for backwards compatibility. Calling it is unnecessary.
/// </summary>
/// <remarks>
/// This will automatically be called once all supported assemblies are loaded into the current AppDomain and so generally is not necessary to call directly.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public static void Unregister()
{
if (!IsRegistered)
{
var error = $"{typeof(MSBuildLocator)}.{nameof(Unregister)} was called, but no MSBuild instance is registered." + Environment.NewLine +
$"Ensure that {nameof(RegisterInstance)}, {nameof(RegisterMSBuildPath)}, or {nameof(RegisterDefaults)} is called before calling this method." + Environment.NewLine +
$"{nameof(IsRegistered)} should be used to determine whether calling {nameof(Unregister)} is a valid operation.";
throw new InvalidOperationException(error);
}

#if NET46
AppDomain.CurrentDomain.AssemblyResolve -= s_registeredHandler;
#else
AssemblyLoadContext.Default.Resolving -= s_registeredHandler;
#endif
}

/// <summary>
Expand Down

0 comments on commit 7f1d5a5

Please sign in to comment.