Skip to content

Commit

Permalink
Make it default for .NET 6
Browse files Browse the repository at this point in the history
  • Loading branch information
dellis1972 committed Mar 28, 2022
1 parent f72a6ae commit 20e10bf
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,6 @@ protected Dictionary<string, int> BuildResourceDesignerFieldLookup (TypeDefiniti
return output;
}

protected Dictionary<string, int> BuildResourceDesignerFieldLookup (TypeDefinition type)
{
var output = new Dictionary<string, int> ();
foreach (TypeDefinition definition in type.NestedTypes)
{
foreach (FieldDefinition field in definition.Fields)
{
string key = $"{definition.Name}::{field.Name}";
if (!output.ContainsKey (key))
output.Add(key, int.Parse (field.Constant?.ToString () ?? "0"));
}
}
return output;
}

protected void FixType (TypeDefinition type, TypeDefinition localDesigner)
{
foreach (MethodDefinition method in type.Methods)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AndroidEnableSGenConcurrent Condition=" '$(AndroidEnableSGenConcurrent)' == '' ">true</AndroidEnableSGenConcurrent>
<AndroidHttpClientHandlerType Condition=" '$(AndroidHttpClientHandlerType)' == '' and '$(UsingAndroidNETSdk)' == 'true' ">Xamarin.Android.Net.AndroidMessageHandler</AndroidHttpClientHandlerType>
<AndroidHttpClientHandlerType Condition=" '$(AndroidHttpClientHandlerType)' == '' and '$(UsingAndroidNETSdk)' != 'true' ">Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<AndroidUseDesignerAssembly Condition=" '$(AndroidUseDesignerAssembly)' == '' ">false</AndroidUseDesignerAssembly>
<AndroidUseDesignerAssembly Condition=" '$(AndroidUseDesignerAssembly)' == '' ">true</AndroidUseDesignerAssembly>
<AndroidGenerateResourceDesigner Condition=" '$(AndroidUseDesignerAssembly)' == 'True' ">false</AndroidGenerateResourceDesigner>
<AndroidGenerateResourceDesigner Condition=" '$(AndroidGenerateResourceDesigner)' == '' ">true</AndroidGenerateResourceDesigner>
<AndroidUseIntermediateDesignerFile Condition=" '$(AndroidUseIntermediateDesignerFile)' == '' ">$(AndroidGenerateResourceDesigner)</AndroidUseIntermediateDesignerFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public partial class Resource : Xamarin.Android.Resource.Designer.Resource {
namespace %NAMESPACE%
type Resource = Xamarin.Android.Resource.Designer.Resource
";

private const string VBTemplate = @"// This is an Auto Generated file DO NOT EDIT
Class Resource
Inherits Xamarin.Android.Resource.Designer.Resource
End Class
";

public string Namespace { get; set; }
Expand All @@ -31,14 +37,16 @@ public override bool RunTask ()
{
var extension = Path.GetExtension (OutputFile.ItemSpec);
var language = string.Compare (extension, ".fs", StringComparison.OrdinalIgnoreCase) == 0 ? "F#" : CodeDomProvider.GetLanguageFromExtension (extension);
//bool isVB = string.Equals (extension, ".vb", StringComparison.OrdinalIgnoreCase);
bool isVB = string.Equals (extension, ".vb", StringComparison.OrdinalIgnoreCase);
bool isFSharp = string.Equals (language, "F#", StringComparison.OrdinalIgnoreCase);
bool isCSharp = string.Equals (language, "C#", StringComparison.OrdinalIgnoreCase);
string template = "";
if (isCSharp)
template = CSharpTemplate.Replace ("%NAMESPACE%", Namespace);
else if (isFSharp)
template = FSharpTemplate.Replace ("%NAMESPACE%", Namespace);
else if (isVB)
template = VBTemplate.Replace ("%NAMESPACE%", Namespace);


File.WriteAllText (OutputFile.ItemSpec, template, System.Text.Encoding.UTF8);
Expand Down
3 changes: 1 addition & 2 deletions src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class RtxtParser {
TaskLoggingHelper log;
Dictionary<string, string> map;

Dictionary<string, string> resource_fixup = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
public Dictionary<string, R> Parse (string file, TaskLoggingHelper logger, Dictionary<string, string> mapping){
log = logger;
map = mapping;
Expand All @@ -47,7 +46,7 @@ void ProcessRtxtFile (string file, Dictionary<string, R> result)
foreach (var line in lines) {
var items = line.Split (new char [] { ' ' }, 4);
int value = items [1] != "styleable" ? Convert.ToInt32 (items [3], 16) : -1;
string itemName = ResourceIdentifier.GetResourceName(items [1], items [2], resource_fixup, log);
string itemName = ResourceIdentifier.GetResourceName(items [1], items [2], map, log);
string itemKey = $"{items [1]}:{itemName}";
switch (items [1]) {
case "anim":
Expand Down
54 changes: 0 additions & 54 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -962,60 +962,6 @@ because xbuild doesn't support framework reference assemblies.
</ItemGroup>
</Target>

<Target Name="_BeforeManagedUpdateAndroidResgen">
<PropertyGroup>
<_ManagedUpdateAndroidResgenInputs>
@(_AndroidMSBuildAllProjects);
@(AndroidResource);
@(AndroidBoundLayout);
@(_MonoAndroidReferencePath);
@(_LibraryResourceDirectoryStamps);
$(_AndroidBuildPropertiesCache);
$(ProjectAssetsFile);
</_ManagedUpdateAndroidResgenInputs>
</PropertyGroup>
<PropertyGroup>
<_ManagedUpdateAndroidResgenInputs Condition="Exists ('$(_AndroidResourcePathsDesignTimeCache)')">$(_ManagedUpdateAndroidResgenInputs);$(_AndroidResourcePathsDesignTimeCache);</_ManagedUpdateAndroidResgenInputs>
<_ManagedUpdateAndroidResgenInputs Condition="Exists ('$(_AndroidLibraryImportsDesignTimeCache)')">$(_ManagedUpdateAndroidResgenInputs);$(_AndroidLibraryImportsDesignTimeCache);</_ManagedUpdateAndroidResgenInputs>
<_ManagedUpdateAndroidResgenInputs Condition="Exists ('$(_AndroidLibraryProjectImportsDesignTimeCache)')">$(_ManagedUpdateAndroidResgenInputs);$(_AndroidLibraryProjectImportsDesignTimeCache);</_ManagedUpdateAndroidResgenInputs>
</PropertyGroup>
</Target>

<!-- Managed DesignTime Resource Generation -->
<Target Name="_ManagedUpdateAndroidResgen" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And '$(AndroidUseDesignerAssembly)' != 'True' "
Inputs="$(_ManagedUpdateAndroidResgenInputs)"
Outputs="$(_AndroidManagedResourceDesignerFile)"
DependsOnTargets="_CreatePropertiesCache;_ExtractLibraryProjectImports;_ValidateAndroidPackageProperties;_GenerateResourceCaseMap;_BeforeManagedUpdateAndroidResgen">
<MakeDir Directories="$(_AndroidIntermediateDesignTimeBuildDirectory)" />
<!-- Parse primary R.java and create Resources.Designer.cs -->
<GenerateResourceDesigner
ContinueOnError="$(DesignTimeBuild)"
NetResgenOutputFile="$(_AndroidManagedResourceDesignerFile)"
JavaResgenInputFile="$(_GeneratedPrimaryJavaResgenFile)"
RTxtFile="$(IntermediateOutputPath)R.txt"
Namespace="$(AndroidResgenNamespace)"
ProjectDir="$(ProjectDir)"
Resources="@(AndroidResource);@(AndroidBoundLayout)"
ResourceDirectory="$(MonoAndroidResourcePrefix)"
AdditionalResourceDirectories="@(LibraryResourceDirectories)"
IsApplication="$(AndroidApplication)"
References="@(_MonoAndroidReferencePath)"
UseManagedResourceGenerator="True"
DesignTimeBuild="$(DesignTimeBuild)"
JavaPlatformJarPath="$(JavaPlatformJarPath)"
ResourceFlagFile="$(_AndroidResFlagFile)"
CaseMapFile="$(_GenerateResourceCaseMapFile)"
Condition="Exists ('$(MonoAndroidResourcePrefix)')"
/>
<Touch Condition="Exists ('$(_AndroidManagedResourceDesignerFile)')" Files="$(_AndroidManagedResourceDesignerFile)" />
<ItemGroup>
<CorrectCasedItem Include="%(Compile.Identity)" Condition="'%(Compile.Identity)' == '$(AndroidResgenFile)'"/>
<CorrectCasedItem Include="%(Compile.Identity)" Condition="'%(Compile.Identity)' == 'Resources\Resource.designer.cs'"/>
<Compile Remove="@(CorrectCasedItem)" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And '%(CorrectCasedItem.Identity)' != '' "/>
<Compile Include="$(_AndroidManagedResourceDesignerFile)" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And Exists ('$(_AndroidManagedResourceDesignerFile)')" />
</ItemGroup>
</Target>

<!-- Resource Build -->

<Target Name="_UpdateAndroidResources"
Expand Down
54 changes: 54 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.DesignTime.targets
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,58 @@ This file is used by all project types, including binding projects.
/>
</Target>

<Target Name="_BeforeManagedUpdateAndroidResgen">
<PropertyGroup>
<_ManagedUpdateAndroidResgenInputs>
@(_AndroidMSBuildAllProjects);
@(AndroidResource);
@(AndroidBoundLayout);
@(_MonoAndroidReferencePath);
@(_LibraryResourceDirectoryStamps);
$(_AndroidBuildPropertiesCache);
$(ProjectAssetsFile);
</_ManagedUpdateAndroidResgenInputs>
</PropertyGroup>
<PropertyGroup>
<_ManagedUpdateAndroidResgenInputs Condition="Exists ('$(_AndroidResourcePathsDesignTimeCache)')">$(_ManagedUpdateAndroidResgenInputs);$(_AndroidResourcePathsDesignTimeCache);</_ManagedUpdateAndroidResgenInputs>
<_ManagedUpdateAndroidResgenInputs Condition="Exists ('$(_AndroidLibraryImportsDesignTimeCache)')">$(_ManagedUpdateAndroidResgenInputs);$(_AndroidLibraryImportsDesignTimeCache);</_ManagedUpdateAndroidResgenInputs>
<_ManagedUpdateAndroidResgenInputs Condition="Exists ('$(_AndroidLibraryProjectImportsDesignTimeCache)')">$(_ManagedUpdateAndroidResgenInputs);$(_AndroidLibraryProjectImportsDesignTimeCache);</_ManagedUpdateAndroidResgenInputs>
</PropertyGroup>
</Target>

<!-- Managed DesignTime Resource Generation -->
<Target Name="_ManagedUpdateAndroidResgen" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And '$(AndroidUseDesignerAssembly)' != 'True' "
Inputs="$(_ManagedUpdateAndroidResgenInputs)"
Outputs="$(_AndroidManagedResourceDesignerFile)"
DependsOnTargets="_CreatePropertiesCache;_ExtractLibraryProjectImports;_ValidateAndroidPackageProperties;_GenerateResourceCaseMap;_BeforeManagedUpdateAndroidResgen">
<MakeDir Directories="$(_AndroidIntermediateDesignTimeBuildDirectory)" />
<!-- Parse primary R.java and create Resources.Designer.cs -->
<GenerateResourceDesigner
ContinueOnError="$(DesignTimeBuild)"
NetResgenOutputFile="$(_AndroidManagedResourceDesignerFile)"
JavaResgenInputFile="$(_GeneratedPrimaryJavaResgenFile)"
RTxtFile="$(IntermediateOutputPath)R.txt"
Namespace="$(AndroidResgenNamespace)"
ProjectDir="$(ProjectDir)"
Resources="@(AndroidResource);@(AndroidBoundLayout)"
ResourceDirectory="$(MonoAndroidResourcePrefix)"
AdditionalResourceDirectories="@(LibraryResourceDirectories)"
IsApplication="$(AndroidApplication)"
References="@(_MonoAndroidReferencePath)"
UseManagedResourceGenerator="True"
DesignTimeBuild="$(DesignTimeBuild)"
JavaPlatformJarPath="$(JavaPlatformJarPath)"
ResourceFlagFile="$(_AndroidResFlagFile)"
CaseMapFile="$(_GenerateResourceCaseMapFile)"
Condition="Exists ('$(MonoAndroidResourcePrefix)')"
/>
<Touch Condition="Exists ('$(_AndroidManagedResourceDesignerFile)')" Files="$(_AndroidManagedResourceDesignerFile)" />
<ItemGroup>
<CorrectCasedItem Include="%(Compile.Identity)" Condition="'%(Compile.Identity)' == '$(AndroidResgenFile)'"/>
<CorrectCasedItem Include="%(Compile.Identity)" Condition="'%(Compile.Identity)' == 'Resources\Resource.designer.cs'"/>
<Compile Remove="@(CorrectCasedItem)" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And '%(CorrectCasedItem.Identity)' != '' "/>
<Compile Include="$(_AndroidManagedResourceDesignerFile)" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And Exists ('$(_AndroidManagedResourceDesignerFile)')" />
</ItemGroup>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved.
<!--
*******************************************
Extensibility hook that allows VS to
provide extra behavior without modifying
provide extra behavior without modifying
the core targets.
*******************************************
-->
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets"
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets')"/>
<PropertyGroup>
<TargetFrameworkIdentifier>MonoAndroid</TargetFrameworkIdentifier>
Expand All @@ -31,16 +31,17 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved.
<NoStdLib>true</NoStdLib>
<!-- Enable nuget package conflict resolution -->
<ResolveAssemblyConflicts>true</ResolveAssemblyConflicts>
<_AndroidResourceDesigner>Resource.designer.vb</_AndroidResourceDesigner>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
<Import Project="Xamarin.Android.Common.targets" />
<!--
*******************************************
Extensibility hook that allows VS to
provide extra behavior without modifying
provide extra behavior without modifying
the core targets.
*******************************************
-->
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>
</Project>

0 comments on commit 20e10bf

Please sign in to comment.