Reputation: 315
I am getting started in the new release of Xamarin as seems allot more stable now for production in 2017 however I am facing an issue of understanding I have my web client calls in a shared library.
Which I want to reference in the standard forms master detail application template but when I go to right click on my forms app there is no add-reference so my question is how do I reference the FuelWc class in my Xamarin forms app.
This is my above project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FuelCallLogDLCore\FuelCallLogDLCore.csproj" />
</ItemGroup>
</Project>
This code is the code which belongs to the main app of Xamarin forms where the views etc are held.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<Reference Include="System">
<HintPath>System</HintPath>
</Reference>
</ItemGroup>
</Project>
So my main question is: how the heck do I reference the code in the shared library?
Usually I would add reference then initiate the object using the standard
Test1 _test = new Test1();
But because I cannot appear to ref the dll, I am at a loss.
Upvotes: 1
Views: 361
Reputation: 12179
There are three alternative methods for sharing code between cross-platform applications:
Shared Projects – Use the Shared Asset Project type to organize your source code, and use #if compiler directives as required to manage platform-specific requirements.
Portable Class Libraries – Create a Portable Class Library (PCL) targetting the platforms you wish to support, and use Interfaces to provide platform-specific functionality.
.NET Standard Libraries – .NET Standard projects work similarly to PCLs, requiring the use of Interfaces to inject platform-specific functionality.
Source: official documentation
I would highly recommend to get familiar with the differences between those methods, so you will be able to decide yourself what should work for your specific case.
Upvotes: 1