Beispiel #1
0
        public XamarinAndroidWearApplicationProject(string debugConfigurationName = "Debug", string releaseConfigurationName = "Release", [CallerMemberName] string packageName = "")
            : base(debugConfigurationName, releaseConfigurationName, packageName)
        {
            TargetFrameworkVersion = Versions.KitkatWatch;
            UseLatestPlatformSdk   = true;
            PackageReferences.Add(KnownPackages.AndroidWear_2_2_0);
            if (Builder.UseDotNet)
            {
                this.AddDotNetCompatPackages();
            }

            MainActivity    = default_main_activity;
            StringsXml      = default_strings_xml;
            LayoutMain      = default_layout_main;
            LayoutRectMain  = default_layout_rect_main;
            LayoutRoundMain = default_layout_round_main;

            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\RectangleMain.axml")
            {
                TextContent = () => LayoutRectMain
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\RoundMain.axml")
            {
                TextContent = () => LayoutRoundMain
            });
        }
Beispiel #2
0
 public XamarinFormsMapsApplicationProject()
 {
     PackageReferences.Add(KnownPackages.XamarinFormsMaps_4_0_0_425677);
     MainActivity = MainActivity.Replace("//${AFTER_FORMS_INIT}", "Xamarin.FormsMaps.Init (this, savedInstanceState);");
     //NOTE: API_KEY metadata just has to *exist*
     AndroidManifest = AndroidManifest.Replace("</application>", "<meta-data android:name=\"com.google.android.maps.v2.API_KEY\" android:value=\"\" /></application>");
 }
Beispiel #3
0
        public XamarinFormsXASdkProject(string outputType = "Exe")
            : base(outputType)
        {
            PackageReferences.Add(KnownPackages.XamarinForms_4_5_0_617);
            // additional deps for XForms on NET5
            // to workaround the issue similar to https://github.com/mono/linker/issues/1139
            PackageReferences.Add(KnownPackages.SystemCodeDom_5_0_0_preview_3_20214_6);
            PackageReferences.Add(KnownPackages.SystemDiagnosticsEventLog_5_0_0_preview_3_20214_6);
            PackageReferences.Add(KnownPackages.SystemDiagnosticsPerformanceCounter_5_0_0_preview_3_20214_6);
            PackageReferences.Add(KnownPackages.SystemIOPorts_5_0_0_preview_3_20214_6);
            PackageReferences.Add(KnownPackages.SystemSecurityPermissions_5_0_0_preview_3_20214_6);
            PackageReferences.Add(KnownPackages.SystemThreadingAccessControl_5_0_0_preview_3_20214_6);

            // Workaround for AndroidX, see: https://github.com/xamarin/AndroidSupportComponents/pull/239
            Imports.Add(new Import(() => "Directory.Build.targets")
            {
                TextContent = () =>
                              @"<Project>
						<PropertyGroup>
							<VectorDrawableCheckBuildToolsVersionTaskBeforeTargets />
						</PropertyGroup>
					</Project>"
            });

            Sources.Add(new AndroidItem.AndroidResource("Resources\\values\\colors.xml")
            {
                TextContent = () => colors_xml,
            });
            Sources.Add(new AndroidItem.AndroidResource("Resources\\values\\styles.xml")
            {
                TextContent = () => styles_xml,
            });
            Sources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Tabbar.xml")
            {
                TextContent = () => Tabbar_xml,
            });
            Sources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Toolbar.xml")
            {
                TextContent = () => Toolbar_xml,
            });
            Sources.Add(new BuildItem("EmbeddedResource", "MainPage.xaml")
            {
                TextContent = MainPageXaml,
            });
            Sources.Add(new BuildItem.Source("MainPage.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(MainPage_xaml_cs),
            });
            Sources.Add(new BuildItem("EmbeddedResource", "App.xaml")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml),
            });
            Sources.Add(new BuildItem.Source("App.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml_cs),
            });

            MainActivity = default_main_activity_cs;
        }
        public XamarinFormsAndroidApplicationProject(string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
            : base(debugConfigurationName, releaseConfigurationName)
        {
            var forms = KnownPackages.XamarinForms_3_1_0_697729;

            PackageReferences.Add(forms);
            PackageReferences.Add(KnownPackages.Android_Arch_Core_Common_26_1_0);
            PackageReferences.Add(KnownPackages.Android_Arch_Lifecycle_Common_26_1_0);
            PackageReferences.Add(KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0);
            PackageReferences.Add(KnownPackages.AndroidSupportV4_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportCompat_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportCoreUI_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportCoreUtils_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportDesign_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportFragment_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportMediaCompat_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportV7AppCompat_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportV7CardView_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportV7MediaRouter_27_0_2_1);
            PackageReferences.Add(KnownPackages.SupportV7RecyclerView_27_0_2_1);
            PackageReferences.Add(KnownPackages.VectorDrawable_27_0_2_1);

            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\colors.xml")
            {
                TextContent = () => colors_xml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\styles.xml")
            {
                TextContent = () => styles_xml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Tabbar.axml")
            {
                TextContent = () => Tabbar_axml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Toolbar.axml")
            {
                TextContent = () => Toolbar_axml,
            });
            OtherBuildItems.Add(new BuildItem("EmbeddedResource", "MainPage.xaml")
            {
                TextContent = () => ProcessSourceTemplate(MainPage_xaml),
            });
            Sources.Add(new BuildItem.Source("MainPage.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(MainPage_xaml_cs),
            });
            OtherBuildItems.Add(new BuildItem("EmbeddedResource", "App.xaml")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml),
            });
            Sources.Add(new BuildItem.Source("App.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml_cs),
            });

            MainActivity = default_main_activity_cs;
        }
Beispiel #5
0
        public XamarinFormsXASdkProject(string outputType = "Exe", [CallerMemberName] string packageName = "")
            : base(outputType, packageName)
        {
            PackageReferences.Add(KnownPackages.XamarinForms_4_7_0_1142);
            this.AddDotNetCompatPackages();

            // Workaround for AndroidX, see: https://github.com/xamarin/AndroidSupportComponents/pull/239
            Imports.Add(new Import(() => "Directory.Build.targets")
            {
                TextContent = () =>
                              @"<Project>
						<PropertyGroup>
							<VectorDrawableCheckBuildToolsVersionTaskBeforeTargets />
						</PropertyGroup>
					</Project>"
            });

            Sources.Add(new AndroidItem.AndroidResource("Resources\\values\\colors.xml")
            {
                TextContent = () => colors_xml,
            });
            Sources.Add(new AndroidItem.AndroidResource("Resources\\values\\styles.xml")
            {
                TextContent = () => styles_xml,
            });
            Sources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Tabbar.xml")
            {
                TextContent = () => Tabbar_xml,
            });
            Sources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Toolbar.xml")
            {
                TextContent = () => Toolbar_xml,
            });
            Sources.Add(new BuildItem("EmbeddedResource", "MainPage.xaml")
            {
                TextContent = MainPageXaml,
            });
            Sources.Add(new BuildItem.Source("MainPage.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(MainPage_xaml_cs),
            });
            Sources.Add(new BuildItem("EmbeddedResource", "App.xaml")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml),
            });
            Sources.Add(new BuildItem.Source("App.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml_cs),
            });

            MainActivity = default_main_activity_cs;
        }
        public XamarinFormsAndroidApplicationProject(string debugConfigurationName = "Debug", string releaseConfigurationName = "Release", [CallerMemberName] string packageName = "")
            : base(debugConfigurationName, releaseConfigurationName, packageName)
        {
            if (Builder.UseDotNet)
            {
                PackageReferences.Add(KnownPackages.XamarinForms_4_7_0_1142);
                this.AddDotNetCompatPackages();
            }
            else
            {
                PackageReferences.Add(KnownPackages.XamarinForms_4_0_0_425677);
            }

            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\colors.xml")
            {
                TextContent = () => colors_xml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\styles.xml")
            {
                TextContent = () => styles_xml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Tabbar.axml")
            {
                TextContent = () => Tabbar_axml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Toolbar.axml")
            {
                TextContent = () => Toolbar_axml,
            });
            OtherBuildItems.Add(new BuildItem("EmbeddedResource", "MainPage.xaml")
            {
                TextContent = MainPageXaml,
            });
            Sources.Add(new BuildItem.Source("MainPage.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(MainPage_xaml_cs),
            });
            OtherBuildItems.Add(new BuildItem("EmbeddedResource", "App.xaml")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml),
            });
            Sources.Add(new BuildItem.Source("App.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml_cs),
            });

            MainActivity = default_main_activity_cs;
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectFile"/> class
        /// based on the given <paramref name="xmlContent"/>.
        /// /// </summary>
        /// <param name="xmlContent">The contents of a MSBuild project file.</param>
        public ProjectFile(string xmlContent)
        {
            var projectFileDocument      = XDocument.Parse(xmlContent);
            var packageReferenceElements = projectFileDocument.Descendants("PackageReference");

            foreach (var packageReferenceElement in packageReferenceElements)
            {
                PackageReferences.Add(new PackageReference(packageReferenceElement.Attribute("Include").Value, packageReferenceElement.Attribute("Version").Value));
            }

            var assemblyReferenceElements = projectFileDocument.Descendants("Reference");

            foreach (var assemblyReference in assemblyReferenceElements)
            {
                AssemblyReferences.Add(new AssemblyReference(assemblyReference.Attribute("Include").Value));
            }
        }
Beispiel #8
0
        public XamarinFormsAndroidApplicationProject(string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
            : base(debugConfigurationName, releaseConfigurationName)
        {
            //NOTE: we can get all the other dependencies transitively, yay!
            PackageReferences.Add(KnownPackages.XamarinForms_3_6_0_220655);

            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\colors.xml")
            {
                TextContent = () => colors_xml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\styles.xml")
            {
                TextContent = () => styles_xml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Tabbar.axml")
            {
                TextContent = () => Tabbar_axml,
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Toolbar.axml")
            {
                TextContent = () => Toolbar_axml,
            });
            OtherBuildItems.Add(new BuildItem("EmbeddedResource", "MainPage.xaml")
            {
                TextContent = () => ProcessSourceTemplate(MainPage_xaml),
            });
            Sources.Add(new BuildItem.Source("MainPage.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(MainPage_xaml_cs),
            });
            OtherBuildItems.Add(new BuildItem("EmbeddedResource", "App.xaml")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml),
            });
            Sources.Add(new BuildItem.Source("App.xaml.cs")
            {
                TextContent = () => ProcessSourceTemplate(App_xaml_cs),
            });

            MainActivity = default_main_activity_cs;
        }
        public XamarinAndroidWearApplicationProject(string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
            : base(debugConfigurationName, releaseConfigurationName)
        {
            TargetFrameworkVersion = Versions.KitkatWatch;
            UseLatestPlatformSdk   = false;
            PackageReferences.Add(KnownPackages.AndroidSupportV13Kitkat);
            PackageReferences.Add(KnownPackages.AndroidWear);

            MainActivity    = default_main_activity;
            StringsXml      = default_strings_xml;
            LayoutMain      = default_layout_main;
            LayoutRectMain  = default_layout_rect_main;
            LayoutRoundMain = default_layout_round_main;

            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\RectangleMain.axml")
            {
                TextContent = () => LayoutRectMain
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\RoundMain.axml")
            {
                TextContent = () => LayoutRoundMain
            });
        }
Beispiel #10
0
        public XamarinFormsMapsApplicationProject([CallerMemberName] string packageName = "")
            : base(packageName: packageName)
        {
            if (Builder.UseDotNet)
            {
                PackageReferences.Add(KnownPackages.XamarinFormsMaps_4_7_0_1142);
                PackageReferences.Add(KnownPackages.Xamarin_GooglePlayServices_Base);
                PackageReferences.Add(KnownPackages.Xamarin_GooglePlayServices_Basement);
                PackageReferences.Add(KnownPackages.Xamarin_GooglePlayServices_Maps);
                PackageReferences.Add(KnownPackages.Xamarin_GooglePlayServices_Tasks);

                //TODO: temporary fix for <Import/> ordering breakage and workloads
                SetProperty("AndroidApplication", "True");
            }
            else
            {
                PackageReferences.Add(KnownPackages.XamarinFormsMaps_4_0_0_425677);
            }
            MainActivity = MainActivity.Replace("//${AFTER_FORMS_INIT}", "Xamarin.FormsMaps.Init (this, savedInstanceState);");
            //NOTE: API_KEY metadata just has to *exist*
            AndroidManifest = AndroidManifest.Replace("</application>", "<meta-data android:name=\"com.google.android.maps.v2.API_KEY\" android:value=\"\" /></application>");
            // From https://github.com/xamarin/GooglePlayServicesComponents/blob/fc057c754e04d3e719d8c111d03d60eb2467b9ce/source/com.google.android.gms/play-services-basement/buildtasks.tests/google-services.json
            OtherBuildItems.Add(new BuildItem("GoogleServicesJson", "google-services.json")
            {
                Encoding    = new System.Text.UTF8Encoding(encoderShouldEmitUTF8Identifier: false),
                TextContent = () =>
                              @"{
  ""project_info"": {
    ""project_number"": ""1041063143217"",
    ""firebase_url"": ""https://white-cedar-97320.firebaseio.com"",
    ""project_id"": ""white-cedar-97320"",
    ""storage_bucket"": ""white-cedar-97320.appspot.com""
  },
  ""client"": [
    {
      ""client_info"": {
        ""mobilesdk_app_id"": ""1:1041063143217:android:ffbe6976403db935"",
        ""android_client_info"": {
          ""package_name"": ""com.xamarin.sample""
        }
      },
      ""oauth_client"": [
        {
          ""client_id"": ""1041063143217-rve97omgqivvs3qcne1ljso137k3t6po.apps.googleusercontent.com"",
          ""client_type"": 1,
          ""android_info"": {
            ""package_name"": ""com.xamarin.sample"",
            ""certificate_hash"": ""84949BBD3F34C8290A55AC9B66AD0A701EBA67AC""
          }
        },
        {
          ""client_id"": ""1041063143217-hu5u4dnv8dkj19i4tpi6piv97kd2k9i0.apps.googleusercontent.com"",
          ""client_type"": 3
        },
        {
          ""client_id"": ""1041063143217-n82odtjjgs9g2qnh1t470mdhj086id9f.apps.googleusercontent.com"",
          ""client_type"": 3
        }
      ],
      ""api_key"": [
        {
          ""current_key"": ""NOT_A_REAL_KEY""
        }
      ],
      ""services"": {
        ""analytics_service"": {
          ""status"": 2,
          ""analytics_property"": {
            ""tracking_id"": ""UA-6465612-26""
          }
        },
        ""appinvite_service"": {
          ""status"": 2,
          ""other_platform_oauth_client"": [
            {
              ""client_id"": ""1041063143217-hu5u4dnv8dkj19i4tpi6piv97kd2k9i0.apps.googleusercontent.com"",
              ""client_type"": 3
            },
            {
              ""client_id"": ""1041063143217-rdc97s7jssl1k29c83b6oci04sihqkdi.apps.googleusercontent.com"",
              ""client_type"": 2,
              ""ios_info"": {
                ""bundle_id"": ""com.xamarin.googleios.collectallthestars""
              }
            }
          ]
        },
        ""ads_service"": {
          ""status"": 2
        }
      }
    }
  ],
  ""configuration_version"": ""1""
}"
            });
        }
        public CsProjectFileDefinition Deserialize(Func <string, string> csprojToLabel,
                                                   IReadOnlyDictionary <string, string> importLabels, string projectFilePath)
        {
            _document = XDocument.Load(projectFilePath);
            var projectFileDir = Path.GetDirectoryName(projectFilePath);

            Type = GetProjectType(_document);

            foreach (var reference in _document.Descendants("PackageReference"))
            {
                var name = reference.Attribute("Include").Value;

                if (importLabels.ContainsKey(name))
                {
                    ProjectReference.Add(importLabels[name]);
                }
                else
                {
                    if (name.Equals("microsoft.net.test.sdk", StringComparison.OrdinalIgnoreCase))
                    {
                        PackageReferences.Add("microsoft.testplatform.testhost");
                        PackageReferences.Add("microsoft.codecoverage");
                    }
                    else
                    {
                        PackageReferences.Add(name);
                    }
                }
            }

            foreach (var frameworkReference in _document.Descendants("FrameworkReference"))
            {
                // TODO naming .Ref?
                var name = frameworkReference.Attribute("Include").Value;
                PackageReferences.Add($"{name}.Ref");
            }

            foreach (var descendant in _document.Descendants("ProjectReference"))
            {
                var include = descendant.Attribute("Include").Value;
                var name    = Path.GetFileNameWithoutExtension(include);

                if (importLabels.ContainsKey(name))
                {
                    ProjectReference.Add(importLabels[name]);
                }
                else
                {
                    ProjectReference.Add(csprojToLabel(Path.Combine(projectFileDir, include)));
                }
            }

            foreach (var bazelDataArray in _document.Descendants("BazelData"))
            {
                BazelData.AddRange(bazelDataArray.Value.Split(';'));
            }

            foreach (var resource in _document.Descendants("EmbeddedResource"))
            {
                var include = resource.Attribute("Include")?.Value;
                var remove  = resource.Attribute("Remove")?.Value;
                var update  = resource.Attribute("Update")?.Value;

                if (include != null)
                {
                    EmbeddedResources.Add(new EmbeddedResourceDefinition(EmbeddedResourceType.Include, include));
                }
                if (remove != null)
                {
                    EmbeddedResources.Add(new EmbeddedResourceDefinition(EmbeddedResourceType.Remove, remove));
                }
                if (update != null)
                {
                    EmbeddedResources.Add(new EmbeddedResourceDefinition(EmbeddedResourceType.Update, update));
                }
            }

            foreach (var copyNode in _document.Descendants("CopyToOutputDirectory"))
            {
                // PreserveNewest ?

                var include = copyNode.Parent?.Attribute("Include")?.Value
                              ?? copyNode.Parent?.Attribute("Update")?.Value;
                if (include != null)
                {
                    CopyToOutput.Add(include.Replace("\\", "/"));
                }
            }

            TestOnly = string.Equals(_document.Descendants("BazelTestOnly").LastOrDefault()?.Value, "true", StringComparison.OrdinalIgnoreCase);

            return(this);
        }