<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Samuel Schumacher</title>
    <description>The latest articles on DEV Community by Samuel Schumacher (@carbonsam).</description>
    <link>https://dev.to/carbonsam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F241148%2Fdea0b021-6175-4079-acd6-bdbec6d0dde6.jpeg</url>
      <title>DEV Community: Samuel Schumacher</title>
      <link>https://dev.to/carbonsam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/carbonsam"/>
    <language>en</language>
    <item>
      <title>Xamarin: Using Multiple Firebase Configuration Files in Android and iOS Projects</title>
      <dc:creator>Samuel Schumacher</dc:creator>
      <pubDate>Tue, 03 Dec 2019 22:06:18 +0000</pubDate>
      <link>https://dev.to/carbonsam/xamarin-using-multiple-firebase-configuration-files-in-android-and-ios-projects-28hd</link>
      <guid>https://dev.to/carbonsam/xamarin-using-multiple-firebase-configuration-files-in-android-and-ios-projects-28hd</guid>
      <description>&lt;p&gt;Need to use different Firebase projects depending on the current build configuration of your Xamarin app? Google has &lt;a href="https://firebase.google.com/docs/projects/multiprojects"&gt;some basic documentation&lt;/a&gt; on this use case, but it didn't quite cut it for me. Hopefully this quick rundown of an &lt;a href="https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-reference"&gt;MSBuild&lt;/a&gt; config helps you out!&lt;/p&gt;

&lt;p&gt;To get started, you will need to download any Android (&lt;code&gt;google-services.json&lt;/code&gt;) or iOS (&lt;code&gt;GoogleService-Info.plist&lt;/code&gt;) project config files from your Firebase console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Android Configuration
&lt;/h2&gt;

&lt;p&gt;First, copy each Firebase project's &lt;code&gt;google-services.json&lt;/code&gt; file into the root of your Android Xamarin project. Rename each file to match the environment it corresponds to, e.g. &lt;code&gt;google-services.release.json&lt;/code&gt; (you may use whatever file naming pattern you wish).&lt;/p&gt;

&lt;p&gt;Example project structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyApp.Android/
-- google-services.debug.json
-- google-services.release.json
-- ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, unload the project and open its configuration file in a text editor. Replace all "google-services" related &lt;code&gt;Include&lt;/code&gt; items with the following lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;GoogleServicesJson Include="google-services.release.json" LogicalName="google-services.json" Condition=" '$(Configuration)' == 'Release' " /&amp;gt;
&amp;lt;GoogleServicesJson Include="google-services.debug.json" LogicalName="google-services.json" Condition=" '$(Configuration)' != 'Release' " /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Make sure to update the filename inside of &lt;code&gt;Include&lt;/code&gt; if you are using a different naming convention.&lt;/p&gt;

&lt;h2&gt;
  
  
  iOS Config
&lt;/h2&gt;

&lt;p&gt;The setup for iOS is very similar.&lt;/p&gt;

&lt;p&gt;First, copy each Firebase project's &lt;code&gt;GoogleService-Info.plist&lt;/code&gt; file into the root of your iOS Xamarin project. Rename each file to match the environment it corresponds to, e.g. &lt;code&gt;GoogleService-Info.release.plist&lt;/code&gt; (you may use whatever file naming pattern you wish).&lt;/p&gt;

&lt;p&gt;Example project structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App.iOS/
-- GoogleService-Info.debug.plist
-- GoogleService-Info.release.plist
-- ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, unload the project and open its configuration file in a text editor. Replace all "GoogleService-Info" related &lt;code&gt;Include&lt;/code&gt; items with the following lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;BundleResource Include="GoogleService-Info.release.plist" LogicalName="GoogleService-Info.plist" Condition=" '$(Configuration)' == 'Release' " /&amp;gt;
&amp;lt;BundleResource Include="GoogleService-Info.debug.plist" LogicalName="GoogleService-Info.plist" Condition=" '$(Configuration)' != 'Release' " /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  How Does it Work?
&lt;/h2&gt;

&lt;p&gt;By setting the &lt;code&gt;LogicalName&lt;/code&gt; property on each file, we are effectively telling MSBuild to use the required name of the file that Firebase counts on - even if we have multiple copies in the same directory.&lt;/p&gt;

&lt;p&gt;Setting a &lt;code&gt;Condition&lt;/code&gt; for each file allows us to selectively import the specific file we need for the current configuration.&lt;/p&gt;

&lt;p&gt;Bookmarks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://firebase.google.com/docs/projects/multiprojects"&gt;Firebase multiple configurations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-reference"&gt;MSBuild reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>xamarin</category>
      <category>firebase</category>
    </item>
  </channel>
</rss>
