Xamarin - Include Settings bundle in certain build

2020-07-17 14:53发布

I am currently building an iOS application using Xamarin and was looking to implement a settings bundle so that our QA department can point the app to the appropriate API environment.

What I am looking at doing is including or excluding the Settings bundle in the Xamarin iOS app based on the build configuration as I may not want to expose this data to the user in Release mode.

Can you include or exclude the Settings bundle or even change the bundle that is compiled into the app based on the build configuration?

2条回答
仙女界的扛把子
2楼-- · 2020-07-17 15:21

(I gotten asked this so many times :-) , I figured I would expand my original answer.)

So as an example, in Debug mode, I want to include a Setting.bundle that consists of Root.plist and a submenu Extra.plist.

In Release mode, I want to include a totally different Root.plist and no Extra.plist in the app's Setting.bundle

My .csproj file is going to look like this:


  <ItemGroup Condition="'$(Configuration)'!='Debug'">
    <BundleResource Include="Settings.bundle\Root.plist" >
    </BundleResource>
  </ItemGroup>
  <ItemGroup Condition="'$(Configuration)'=='Debug'">
    <BundleResource Include="Settings.debug\Extra.plist" >
            <Link>Settings.bundle\Extra.plist</Link>
    </BundleResource>
    <BundleResource Include="Settings.debug\Root.plist" >
            <Link>Settings.bundle\Root.plist</Link>
    </BundleResource>
  </ItemGroup>

Note:

As shown below, in Debug Xamarin is including additional menu items into my Root.plist and in Release they are not. Also my Additional Settings submenu is no longer available and now are labeled with XXXX Release

Debug mode result:

enter image description here

enter image description here

Release mode result:

enter image description here

查看更多
闹够了就滚
3楼-- · 2020-07-17 15:31

Apart from conditional including of different settings bundle you will probably also need to conditionally read the settings in your app. You can use conditional compilation to either read from settings or use hard coded values:

#if DEBUG
 //Read from settings
#else
 //Use other values.
#endif
查看更多
登录 后发表回答