diff --git a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs
index a08447e838f..d5ca2e4c65c 100644
--- a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs
+++ b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs
@@ -20,7 +20,7 @@ namespace MonoDroid.Tuner
public class FixLegacyResourceDesignerStep : LinkDesignerBase
{
internal const string DesignerAssemblyName = "_Microsoft.Android.Resource.Designer";
- internal const string DesignerAssemblyNamespace = "Microsoft.Android.Resource.Designer";
+ internal const string DesignerAssemblyNamespace = "_Microsoft.Android.Resource.Designer";
bool designerLoaded = false;
AssemblyDefinition designerAssembly = null;
diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs
index ba009724f7b..3675c1a90bb 100644
--- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs
@@ -103,20 +103,25 @@ bool Run(DirectoryAssemblyResolver res)
} else {
// Add the InternalsVisibleToAttribute so the app can access ResourceConstant
if (!string.IsNullOrEmpty (AssemblyName)) {
- MethodReference internalsVisibleToAttributeConstructor = ImportCustomAttributeConstructor ("System.Runtime.CompilerServices.InternalsVisibleToAttribute", module, netstandardDef.MainModule);
+ MethodReference internalsVisibleToAttributeConstructor = ImportCustomAttributeConstructor ("System.Runtime.CompilerServices.InternalsVisibleToAttribute", module, netstandardDef.MainModule, argCount: 1);
var ar = new CustomAttribute (internalsVisibleToAttributeConstructor);
ar.ConstructorArguments.Add (new CustomAttributeArgument (module.TypeSystem.String, AssemblyName));
module.Assembly.CustomAttributes.Add (ar);
}
}
- MethodReference targetFrameworkConstructor = ImportCustomAttributeConstructor ("System.Runtime.Versioning.TargetFrameworkAttribute", module, netstandardDef.MainModule);
+ MethodReference targetFrameworkConstructor = ImportCustomAttributeConstructor ("System.Runtime.Versioning.TargetFrameworkAttribute", module, netstandardDef.MainModule, argCount: 1);
var attr = new CustomAttribute (targetFrameworkConstructor);
attr.ConstructorArguments.Add (new CustomAttributeArgument (module.TypeSystem.String, $".NETStandard,Version=v2.1"));
attr.Properties.Add (new CustomAttributeNamedArgument ("FrameworkDisplayName", new CustomAttributeArgument (module.TypeSystem.String, "")));
module.Assembly.CustomAttributes.Add (attr);
+ MethodReference editorBrowserConstructor = ImportCustomAttributeConstructor ("System.ComponentModel.EditorBrowsableAttribute", module, netstandardDef.MainModule, argCount: 1);
+ TypeReference e = ImportType ("System.ComponentModel.EditorBrowsableState", module, netstandardDef.MainModule);
+ var editorBrowserAttr = new CustomAttribute (editorBrowserConstructor);
+ editorBrowserAttr.ConstructorArguments.Add (new CustomAttributeArgument (e, System.ComponentModel.EditorBrowsableState.Never));
+
var att = TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
intArray = new ArrayType (module.TypeSystem.Int32);
@@ -131,6 +136,7 @@ bool Run(DirectoryAssemblyResolver res)
objectRef
);
CreateCtor (resourceDesigner, module);
+ resourceDesigner.CustomAttributes.Add (editorBrowserAttr);
module.Types.Add (resourceDesigner);
TypeDefinition constDesigner = null;
if (IsApplication) {
@@ -143,6 +149,7 @@ bool Run(DirectoryAssemblyResolver res)
objectRef
);
CreateCtor (constDesigner, module);
+ constDesigner.CustomAttributes.Add (editorBrowserAttr);
module.Types.Add (constDesigner);
}
@@ -196,11 +203,16 @@ bool Run(DirectoryAssemblyResolver res)
return !Log.HasLoggedErrors;
}
- MethodReference ImportCustomAttributeConstructor (string type, ModuleDefinition module, ModuleDefinition sourceModule = null)
+ MethodReference ImportCustomAttributeConstructor (string type, ModuleDefinition module, ModuleDefinition sourceModule = null, int argCount = 0)
{
var tr = module.ImportReference ((sourceModule ?? module).ExportedTypes.First(x => x.FullName == type).Resolve ());
var tv = tr.Resolve();
- return module.ImportReference (tv.Methods.First(x => x.IsConstructor));
+ return module.ImportReference (tv.Methods.First(x => x.IsConstructor && (x.Parameters?.Count ?? 0) == argCount));
+ }
+
+ TypeReference ImportType (string type, ModuleDefinition module, ModuleDefinition sourceModule = null)
+ {
+ return module.ImportReference ((sourceModule ?? module).ExportedTypes.First(x => x.FullName == type).Resolve ());
}
void CreateIntProperty (string resourceClass, string propertyName, int value, TypeDefinition resourceDesigner, ModuleDefinition module,
diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerIntermediateClass.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerIntermediateClass.cs
index 9247993a554..b6d89a6aaf6 100644
--- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerIntermediateClass.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerIntermediateClass.cs
@@ -15,15 +15,25 @@ public class GenerateResourceDesignerIntermediateClass : AndroidTask
private const string ResourceDesigner = $"{FixLegacyResourceDesignerStep.DesignerAssemblyNamespace}.Resource";
private const string ResourceDesignerConstants = $"{FixLegacyResourceDesignerStep.DesignerAssemblyNamespace}.ResourceConstant";
- private const string CSharpTemplate = @"// This is an Auto Generated file DO NOT EDIT
+ private const string CSharpTemplate = @"//------------------------------------------------------------------------------
+//
+// This code was generated by a tool. DO NOT EDIT
+//
+//------------------------------------------------------------------------------
using System;
namespace %NAMESPACE% {
+ #pragma warning disable IDE0002
public partial class Resource : %BASECLASS% {
}
+ #pragma warning restore IDE0002
}
";
- private const string FSharpTemplate = @"// This is an Auto Generated file DO NOT EDIT
+ private const string FSharpTemplate = @"//------------------------------------------------------------------------------
+//
+// This code was generated by a tool. DO NOT EDIT
+//
+//------------------------------------------------------------------------------
namespace %NAMESPACE%
type Resource = %BASECLASS%