Search code examples
c#xamarin.formssolution

Xamarin Forms Solution based on existing standard solution


Im looking for a way to extend a working standard Xamarin Forms solution with its own git repository with another customer specific solution taht should have its own project as extra to the solution.

STANDARD SOLUTION Projects UWP DROID IOS Application (.net standard ) CORE (.net standard )

The new Solution should use the existing solution. CUSTOMER SOLUTION ADD EXISTING (Project) UWP DROID IOS Application (.net standard ) CORE (.net standard )

When only the original projects are added, everythings works as expected. SO how to add the custom project and logic to the new solution.

I was hoping to add project to the Customer solution using something like this. Some inject or discover ICustomerProjectAdapter during startup. I tried

[assembly: Xamarin.Forms.Dependency(typeof(CustomTemplateAdapter))]
namespace CustomTemplate
{
    public class CustomTemplateAdapter : ICustomerProjectAdapter
    {
        public string Test { get { return "HELLO WORLD - Custom Template";}  }
    }
}

but this didnt work CustomerProjectAdapter was always null.

var CustomerProjectAdapter = DependencyService.Get<ICustomerProjectAdapter>();

How can we use a standard Xamarin forms Solution and extend it using a second repository/2nd solution and have some form of injection to use a extra Project.

Each customer solution would use this process. I dont want to add customer specific code into the Main repository. Using customer specific configurations or having customer specific sections in csproj file would be ok. At code level also adding customer section would be ok if it is restricted a singe injection point.

I also tried adding references to MAIN cs.proj using a pre compile time script. this resulted in Not found errors in Visual studio when switch between solutions. . But even with the csproj changed at compile time, the discovery/inject problem still wasnt solved.

How do i best solve this type of problem?


Solution

  • So in case someone is looking for such a solution I got conditions in project file working. It solves the problem nicely.

    The only compromise and reference to customer code or projects is restricted to one project and is only inside the csproj file. We have a fascade project responsible for returning an instance of a custom-adpater that resides in another project. This project is referenced at build time.

    Compile and syntax checks inside VS all work based on the solution currently open.

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
      </PropertyGroup>
    
    <Choose>
      <When Condition="'$(SolutionName)' == 'MyCustomSolution' ">
        <ItemGroup>
          <ProjectReference Include="..\..\XPC_CustomRepos\CUSTOMERn\Customern.csproj">
            <Name>XYZ.CustomAdapter</Name>
          </ProjectReference>
        </ItemGroup>
      </When>
    
    <!-- Repeat for each custom solution -->
    
      <Otherwise>
        <ItemGroup>
          <ProjectReference Include="..\STANDARD.Adapter\XYZ.Adapter.csproj">
            <Name>XYZ.Standard</Name>
          </ProjectReference>
        </ItemGroup>
      </Otherwise>  
    
    </Choose>
    
    </Project>