dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

Auto generated Resource.designer.cs not using global:: for attribute #3744

Closed Doraku closed 4 years ago

Doraku commented 5 years ago

Steps to Reproduce

  1. use https://github.com/onovotny/MSBuildSdkExtras in a csproj to build multitarget dll (uses this tool internally):

    <Project Sdk="MSBuild.Sdk.Extras/2.0.54">
    <PropertyGroup Label="Compilation">
    <LangVersion>latest</LangVersion>
    <TargetFrameworks>
      net48;
      netcoreapp3.0;
      monoandroid90;
    </TargetFrameworks>
    <Optimize>true</Optimize>
    <Configurations>Debug;Release</Configurations>
    </PropertyGroup>
    
    <PropertyGroup Label="Debug" Condition="'$(Configuration)'=='Debug'">
    <Optimize>false</Optimize>
    <DefineConstants>DEBUG</DefineConstants>
    </PropertyGroup>
    ...
    </Project>
  2. add a type in the <project>.System namespace

  3. bonus: add a type in the <project>.Resource namespace

Expected Behavior

Build correctly

Actual Behavior

  1. Complains for the monoandroid target because of the conflict in the auto generated Resource.designer.cs file:
    
    #pragma warning disable 1591
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.42000
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

[assembly: global::Android.Runtime.ResourceDesignerAttribute("Talio.Resource", IsApplication=false)]

namespace Talio {

//!!!!! should be [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{

    static Resource()
    {
        global::Android.Runtime.ResourceIdManager.UpdateIdValues();
    }

    public partial class Attribute
    {

        static Attribute()
        {
            global::Android.Runtime.ResourceIdManager.UpdateIdValues();
        }

        private Attribute()
        {
        }
    }
}

}

pragma warning restore 1591


3. Complains because of the conflict of the Resource namespace and type (I don't have a Resource file in my project, is this even required since it's empty?)

Both of these can be worked around by renaming the namespaces but I still think we shouldn't have to do this.

### Version Information
Microsoft Visual Studio Community 2019
Version 16.3.2
VisualStudio.16.Release/16.3.2+29326.143
Microsoft .NET Framework
Version 4.8.03752

Xamarin   16.3.0.274 (d16-3@06531f8)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.3.0.246 (remotes/origin/d16-3@bd2f86892)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.3.565 (27e9746)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   10.0.0.43 (d16-3/8af1ca8)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: mono/mono/2019-06@7af64d1ebe9
    Java.Interop: xamarin/java.interop/d16-3@5836f58
    LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
    LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.27.1@8212a2d
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333

Hope this is related here, thank you for your assistance :)
dellis1972 commented 4 years ago

This is fixed via

https://github.com/xamarin/xamarin-android/commit/65b5c615674387dc8f212f79ce72abea85bdf4d1#diff-45ffe90851907e18e64026545cf07e2b https://github.com/xamarin/xamarin-android/commit/d18c824c9e96dac59d75be3da2b46fecd18ade51#diff-45ffe90851907e18e64026545cf07e2b

Both of which should be in d16-7 or d17-8 preview.