Don't look up CurrentAddin by assemblies loaded.
CurrentAddin - at least in tests - will use something like UnitTests.dll
which is not always loaded via the non-expensive check.
Use AssemblyName.GetName instead of adding new API
Uncovered by https://github.com/mono/monodevelop/issues/4237
```
"/home/pi/sources/monodevelop/main/Main.sln" (default target) (1) ->
"/home/pi/sources/monodevelop/main/src/core/MonoDevelop.Startup/MonoDevelop.Startup.csproj" (default target) (13) ->
"/home/pi/sources/monodevelop/main/external/mono-addins/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.csproj" (default target) (14:2) ->
Mono.Addins.CecilReflector/Reflector.cs(373,3): error CS0012: The type `System.Collections.Generic.ISet`1<T>' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' [/home/pi/sources/monodevelop/main/external/mono-addins/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.csproj]
```
The VSMac 2017-08 branch build breaks with mono 5.6.0.x:
Using "ReportAssetsLogMessages" task from assembly "/usr/local/share/dotnet/sdk/2.0.0/Sdks/Microsoft.NET.Sdk/build/../tools/net46/Microsoft.NET.Build.Tasks.dll".
Task "ReportAssetsLogMessages"
/usr/local/share/dotnet/sdk/2.0.0/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(323,5): error MSB4018: The "ReportAssetsLogMessages" task failed unexpectedly. [/Users/ludovic/Xamarin/monodevelop/main/external/RefactoringEssentials/RefactoringEssentials.2017/RefactoringEssentials.csproj]
/usr/local/share/dotnet/sdk/2.0.0/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(323,5): error MSB4018: System.TypeLoadException: Could not resolve type with token 0100005b (from typeref, class/assembly NuGet.ProjectModel.IAssetsLogMessage, NuGet.ProjectModel, Version=4.3.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35) [/Users/ludovic/Xamarin/monodevelop/main/external/RefactoringEssentials/RefactoringEssentials.2017/RefactoringEssentials.csproj]
/usr/local/share/dotnet/sdk/2.0.0/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(323,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <01420900fd004c128de2d2ee31bad624>:0 [/Users/ludovic/Xamarin/monodevelop/main/external/RefactoringEssentials/RefactoringEssentials.2017/RefactoringEssentials.csproj]
/usr/local/share/dotnet/sdk/2.0.0/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(323,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in <765502eb2f884ce79731edeb4b0517fb>:0 [/Users/ludovic/Xamarin/monodevelop/main/external/RefactoringEssentials/RefactoringEssentials.2017/RefactoringEssentials.csproj]
/usr/local/share/dotnet/sdk/2.0.0/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(323,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder+<ExecuteInstantiatedTask>d__26.MoveNext () [0x0022d] in <765502eb2f884ce79731edeb4b0517fb>:0 [/Users/ludovic/Xamarin/monodevelop/main/external/RefactoringEssentials/RefactoringEssentials.2017/RefactoringEssentials.csproj]
The missing token token 0100005b (from typeref, class/assembly NuGet.ProjectModel.IAssetsLogMessage, NuGet.ProjectModel, Version=4.3.0.5)
is referenced from the `Microsoft.NET.Build.Tasks.dll`. The
`NuGet.ProjectModel.dll` next to the tasks assembly has the type
available. But looking at assembly loader logs, it turns out that the
assembly is actually being loaded via a raw byte[] instead of from the
file.
More digging reveals that this is being done by
`Costura.AssemblyLoader`[1] which was loading the assembly from embedded
resources in `NuGet.Build.Packaging.Tasks.dll` assembly:
1e70e0: costura.nuget.projectmodel.dll.zip (size 55791)
And this seems to be out of sync with the nuget assemblies bundled with
the `Microsoft.NET.Build.Tasks.dll`.
`NuGet.Build.Packaging.Tasks`'s `ReadLegacyDependencies` targets gets
triggered because `Mono.Addins.csproj` has `PackOnBuild=true` for
Release builds. Hence, the issue is never seen in debug builds.
The `Costura` change was reverted in the nuget package upstream[2] but
that was committed after `v0.1.276`, which is the version being used currently.
So, we bump to latest version of the package - `v0.2.0`.
--
1. https://github.com/Fody/Costura
2. 7838a0a95f
The reflector now takes into account that some assemblies only have to
be loaded if they reference Mono.Addins. For example, when looking for
a subclass of Mono.Addins.ExtensionNode, only assemblies that have a
Mono.Addins reference can define such class.
This optimization can be applied in several cases and reduces the
number of assemblies that are loaded.
An UnloadAssembly method has also been added, and it is used to unload
potential add-in assemblies when there is an error while scanning.
If anyone tried to build mono-addins with the xbuild 12.0 engine [1]
that comes with mono 4.2.1 [2] (quite widespread given that it's the
version bundled with Ubuntu 16.04.x LTS), the build would not
work [3].
[1] $ xbuild --version
XBuild Engine Version 12.0
Mono, Version 4.2.1.0
Copyright (C) 2005-2013 Various Mono authors
[2] $ mono --version
Mono JIT compiler version 4.2.1 (Debian 4.2.1.102+dfsg2-7ubuntu4)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen
[3]
$ ./autogen.sh
I am going to run ./configure with no arguments - if you wish
to pass any to it, please specify them on the ./autogen.sh command line.
Running aclocal -I . ...
Running automake --gnu ...
<snip />
$ make
Making all in Mono.Addins
make[1]: Entering directory '/home/andres/Documents/Code/OpenSource/mono-addins/Mono.Addins'
sed -e "s/@ASSEMBLY_NAME@/Mono.Addins/" -e "s/@POLICY@/0.2/" ../policy.config > policy.0.2.config
/usr/bin/al -link:policy.0.2.config -out:policy.0.2.Mono.Addins.dll -keyfile:../mono-addins.snk
ALINK: warning A99999: Path 'policy.0.2.config' in the resource name is not supported. Using just file name 'policy.0.2.config'
sed -e "s/@ASSEMBLY_NAME@/Mono.Addins/" -e "s/@POLICY@/0.3/" ../policy.config > policy.0.3.config
/usr/bin/al -link:policy.0.3.config -out:policy.0.3.Mono.Addins.dll -keyfile:../mono-addins.snk
ALINK: warning A99999: Path 'policy.0.3.config' in the resource name is not supported. Using just file name 'policy.0.3.config'
sed -e "s/@ASSEMBLY_NAME@/Mono.Addins/" -e "s/@POLICY@/0.4/" ../policy.config > policy.0.4.config
/usr/bin/al -link:policy.0.4.config -out:policy.0.4.Mono.Addins.dll -keyfile:../mono-addins.snk
ALINK: warning A99999: Path 'policy.0.4.config' in the resource name is not supported. Using just file name 'policy.0.4.config'
sed -e "s/@ASSEMBLY_NAME@/Mono.Addins/" -e "s/@POLICY@/0.5/" ../policy.config > policy.0.5.config
/usr/bin/al -link:policy.0.5.config -out:policy.0.5.Mono.Addins.dll -keyfile:../mono-addins.snk
ALINK: warning A99999: Path 'policy.0.5.config' in the resource name is not supported. Using just file name 'policy.0.5.config'
sed -e "s/@ASSEMBLY_NAME@/Mono.Addins/" -e "s/@POLICY@/0.6/" ../policy.config > policy.0.6.config
/usr/bin/al -link:policy.0.6.config -out:policy.0.6.Mono.Addins.dll -keyfile:../mono-addins.snk
ALINK: warning A99999: Path 'policy.0.6.config' in the resource name is not supported. Using just file name 'policy.0.6.config'
Building Mono.Addins.csproj
CSC: error CS0518: The predefined type `System.Object' is not defined or imported
CSC: error CS0518: The predefined type `System.ValueType' is not defined or imported
CSC: error CS0518: The predefined type `System.Attribute' is not defined or imported
CSC: error CS0518: The predefined type `System.Int32' is not defined or imported
CSC: error CS0518: The predefined type `System.UInt32' is not defined or imported
CSC: error CS0518: The predefined type `System.Int64' is not defined or imported
CSC: error CS0518: The predefined type `System.UInt64' is not defined or imported
CSC: error CS0518: The predefined type `System.Single' is not defined or imported
CSC: error CS0518: The predefined type `System.Double' is not defined or imported
CSC: error CS0518: The predefined type `System.Char' is not defined or imported
CSC: error CS0518: The predefined type `System.Int16' is not defined or imported
CSC: error CS0518: The predefined type `System.Decimal' is not defined or imported
CSC: error CS0518: The predefined type `System.Boolean' is not defined or imported
CSC: error CS0518: The predefined type `System.SByte' is not defined or imported
CSC: error CS0518: The predefined type `System.Byte' is not defined or imported
CSC: error CS0518: The predefined type `System.UInt16' is not defined or imported
CSC: error CS0518: The predefined type `System.String' is not defined or imported
CSC: error CS0518: The predefined type `System.Enum' is not defined or imported
CSC: error CS0518: The predefined type `System.Delegate' is not defined or imported
CSC: error CS0518: The predefined type `System.MulticastDelegate' is not defined or imported
CSC: error CS0518: The predefined type `System.Void' is not defined or imported
CSC: error CS0518: The predefined type `System.Array' is not defined or imported
CSC: error CS0518: The predefined type `System.Type' is not defined or imported
CSC: error CS0518: The predefined type `System.Collections.IEnumerator' is not defined or imported
CSC: error CS0518: The predefined type `System.Collections.IEnumerable' is not defined or imported
CSC: error CS0518: The predefined type `System.IDisposable' is not defined or imported
CSC: error CS0518: The predefined type `System.IntPtr' is not defined or imported
CSC: error CS0518: The predefined type `System.UIntPtr' is not defined or imported
CSC: error CS0518: The predefined type `System.RuntimeFieldHandle' is not defined or imported
CSC: error CS0518: The predefined type `System.RuntimeTypeHandle' is not defined or imported
CSC: error CS0518: The predefined type `System.Exception' is not defined or imported
Makefile:571: recipe for target 'csproj_build' failed
make[1]: *** [csproj_build] Error 1
make[1]: Leaving directory '/home/andres/Documents/Code/OpenSource/mono-addins/Mono.Addins'
Makefile:351: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
.NET is more strict than Mono when resolving a type constructor.
Mono can resolve a constructor with an enum parameter by providing
an integer as parameter value. .NET fails in that case.
Sometimes dependent assemblies cannot be loaded. This scenario does not
always mean the addin is broken, so wrap a try/catch around scanning
dependent assemblies and log/ignore any failures.
This will allow the csproj files to be directly
usable in the monodevelop build. I've also changed
the gtk-sharp references to not require an exact version
to aid building on multiple platforms.