Search code examples
visual-studioxamarinazure-devopsbuildconfigurationvisual-studio-app-center

Specify Project References Based On Build Configuration in Xamarin-Visual Studio (VSTS + App Center)


enter image description here

As you can see in the above picture, I am trying to create a Xamarin Forms Application. The application is basically a retail utility app which will be targeted for the region US & Japan.

In the given Project structure SuppplyApp.Main is the Xamarin Forms entry project, which is being navigated from iOS and Android Project.

And SupplyApp.Japan & SupplyApp.US are the specific features for the regions US and Japan respectively.

In effect, I would like to use the combination of these based on the configuration.(eg:- SupplyApp.Main + SupplyApp.US OR SupplyApp.Main + SupplyApp.Japan)

I am using the combination of VSTS and Visual Studio App Center for my CICD & Distribution.

Here my doubt is during the time of build creation, is it possible to refer Projects (SupplyApp.US / SupplyApp.Japan) based on some build configuration. Or If it is not available through VSTS, how I can achieve the same using Visual Studio.

Can someone please guide me to solve this issue. I have found few solutions based on traditional .Net project, But I haven't find something similar for Xamarin.


Solution

  • The project reference information is stored in project file, so it’s better to configure it in project file per to different configuration (Right click project in VS >Unload project >Right click project >Edit xxx.proj), for example:

    <ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <ProjectReference Include="..\ClassLibrary2\ClassLibrary2.csproj">
          <Project>{08adf376-babd-4d9c-8d7b-9d40cf04745d}</Project>
          <Name>ClassLibrary2</Name>
        </ProjectReference>
      </ItemGroup>
    

    You can create multiple configurations by right clicking the solution > Configuration Manager > Click dropdownlist control of configuration > New > Specify name and check Create a project configuration.

    After that, you can specify different configuration in VSTS Build (e.g. Configuration and Platform in Visual Studio Build task)