Beispiel #1
0
    void ExecuteWeavers()
    {
        foreach (var weaver in weaverInstances)
        {
            if (cancelRequested)
            {
                return;
            }

            try
            {
                cancelDelegate = weaver.Instance.Cancel;

                Logger.SetCurrentWeaverName(weaver.Config.ElementName);
                var startNew = Stopwatch.StartNew();
                Logger.LogInfo("  Executing Weaver ");
                Logger.LogDebug($"  Configuration source: {weaver.Config.ConfigurationSource}");
                try
                {
                    weaver.Instance.Execute();
                }
                catch (WeavingException)
                {
                    throw;
                }
                catch (MissingMemberException exception) when(weaver.IsUsingOldFodyVersion)
                {
                    throw new WeavingException($"Failed to execute weaver {weaver.Config.AssemblyPath} due to a MissingMemberException. Message: {exception.Message}. This is likely due to the weaver referencing an old version ({weaver.FodyVersion}) of Fody.");
                }
                catch (FileNotFoundException exception) when(exception.Message.Contains(nameof(ValueTuple)))
                {
                    throw new Exception($@"Failed to execute weaver {weaver.Config.AssemblyPath} due to a failure to load ValueTuple.
This is a known issue with in dotnet (https://github.com/dotnet/runtime/issues/27533).
The recommended work around is to avoid using ValueTuple inside a weaver.", exception);
                }
                catch (Exception exception)
                {
                    throw new Exception($"Failed to execute weaver {weaver.Config.AssemblyPath}", exception);
                }

                var finishedMessage = $"  Finished '{weaver.Config.ElementName}' in {startNew.ElapsedMilliseconds}ms {Environment.NewLine}";
                Logger.LogDebug(finishedMessage);

                ReferenceCleaner.CleanReferences(ModuleDefinition, weaver.Instance, Logger.LogDebug);
            }
            finally
            {
                cancelDelegate = null;
                Logger.ClearWeaverName();
            }
        }
    }
Beispiel #2
0
    void ExecuteWeavers()
    {
        foreach (var weaver in weaverInstances)
        {
            if (cancelRequested)
            {
                return;
            }

            try
            {
                cancelDelegate = weaver.Instance.Cancel;

                Logger.SetCurrentWeaverName(weaver.Config.ElementName);
                var startNew = Stopwatch.StartNew();
                Logger.LogInfo("  Executing Weaver ");
                Logger.LogDebug($"  Configuration source: {weaver.Config.ConfigurationSource}");
                try
                {
                    weaver.Instance.Execute();
                }
                catch (WeavingException)
                {
                    throw;
                }
                catch (MissingMemberException exception) when(weaver.IsUsingOldFodyVersion)
                {
                    throw new WeavingException($"Failed to execute weaver {weaver.Config.AssemblyPath} due to a MissingMemberException. Message: {exception.Message}. This is likely due to the weaver referencing an old version ({weaver.FodyVersion}) of Fody.");
                }
                catch (Exception exception)
                {
                    throw new Exception($"Failed to execute weaver {weaver.Config.AssemblyPath}", exception);
                }

                var finishedMessage = $"  Finished '{weaver.Config.ElementName}' in {startNew.ElapsedMilliseconds}ms {Environment.NewLine}";
                Logger.LogDebug(finishedMessage);

                ReferenceCleaner.CleanReferences(ModuleDefinition, weaver.Instance, Logger.LogDebug);
            }
            finally
            {
                cancelDelegate = null;
                Logger.ClearWeaverName();
            }
        }
    }
Beispiel #3
0
    void ExecuteWeavers()
    {
        foreach (var weaver in weaverInstances)
        {
            if (cancelRequested)
            {
                return;
            }

            try
            {
                cancelDelegate = weaver.Instance.Cancel;

                Logger.SetCurrentWeaverName(weaver.Config.ElementName);
                var startNew = Stopwatch.StartNew();
                Logger.LogInfo("  Executing Weaver ");
                try
                {
                    weaver.Instance.Execute();
                }
                catch (WeavingException)
                {
                    throw;
                }
                catch (Exception exception)
                {
                    throw new Exception($"Failed to execute weaver {weaver.Config.AssemblyPath}", exception);
                }

                var finishedMessage = $"  Finished '{weaver.Config.ElementName}' in {startNew.ElapsedMilliseconds}ms {Environment.NewLine}";
                Logger.LogDebug(finishedMessage);

                ReferenceCleaner.CleanReferences(ModuleDefinition, weaver.Instance, Logger.LogDebug);
            }
            finally
            {
                cancelDelegate = null;
                Logger.ClearWeaverName();
            }
        }
    }
Beispiel #4
0
    void ExecuteWeavers()
    {
        foreach (var weaver in weaverInstances)
        {
            if (cancelRequested)
            {
                return;
            }

            try
            {
                if (weaver.WeaverDelegate.Cancel != null)
                {
                    cancelDelegate = () => weaver.WeaverDelegate.Cancel(weaver.Instance);
                }

                Logger.SetCurrentWeaverName(weaver.Config.AssemblyName);
                var startNew = Stopwatch.StartNew();
                Logger.LogDebug("  Executing Weaver ");
                weaver.WeaverDelegate.Execute(weaver.Instance);
                var finishedMessage = $"  Finished '{weaver.Config.AssemblyName}' in {startNew.ElapsedMilliseconds}ms {Environment.NewLine}";
                Logger.LogDebug(finishedMessage);
#pragma warning disable 618
                if (weaver.Instance is BaseModuleWeaver baseModuleWeaver)
                {
                    ReferenceCleaner.CleanReferences(ModuleDefinition, baseModuleWeaver, Logger.LogDebug);
                }
#pragma warning restore 618
            }
            finally
            {
                cancelDelegate = null;
                Logger.ClearWeaverName();
            }
        }
    }