2

I'm creating a multi-targeted class library for a Xamarin Forms project which will be targeted to .NET Standard 2.0, MonoAndroid 8.1, and Xamarin.iOS 1.0. I understand how to conditionally include files for compilation based upon the platform, to include platform specific renderers and utilities.

I need to know how to include *.xaml files in a way that won't break resharper and intellisense, and won't emit false positives for InitializeComponent being out of context in a ContentPage. Setting the xaml files to build action EmbeddedResource, with custom tool UpdateDesignTimeXaml in the csproj, and the code behind files to Compile, partial classes aren't detected, resharper stops being helpful, etc.

What do the csproj files for your multi-targeted projects targeting these platforms and containing xaml resources look like?

Max Hampton
  • 1,254
  • 9
  • 20

1 Answers1

0

I created a new Multitargetproject from the ground up and now i can also include Xaml Files. The only problem i have is, that when i add for example Test.shared.xaml or Test.shared.cs i have to go to the project file and remove the following generated lines:

<Project Sdk="MSBuild.Sdk.Extras">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;netcoreapp2.0;net461;MonoAndroid90;Xamarin.iOS10</TargetFrameworks>

    <Product>$(AssemblyName) ($(TargetFramework))</Product>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <AssemblyFileVersion>1.0.0.0</AssemblyFileVersion>
    <Version>1.0.0.0</Version>
    <PackageVersion>1.0.0.0</PackageVersion>
    <PackOnBuild>true</PackOnBuild>
    <NeutralLanguage>en</NeutralLanguage>
    <LangVersion>default</LangVersion>
    <DefineConstants>$(DefineConstants);</DefineConstants>

    <UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>

    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <GenerateDocumentationFile>false</GenerateDocumentationFile>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)'=='Release' ">
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <DebugType>pdbonly</DebugType>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.shared.cs" />
    <Compile Include="**\*.shared.xaml.cs" />
  </ItemGroup>
    <ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) ">
    <Compile Include="**\*.android.cs" />
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('Xamarin.iOS')) ">
    <Compile Include="**\*.apple.cs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.3.0.819712-pre2" />
    <PackageReference Include="Xamarin.Forms.PancakeView" Version="1.2.1" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid90'">
    <PackageReference Include="Plugin.CurrentActivity">
      <Version>2.1.0.4</Version>
    </PackageReference>
  </ItemGroup>

</Project>

And also the global.json which sould be in the root of the project

  "sdk": {
    "version": "3.0.100-preview"
  },
  "msbuild-sdks": {
    "MSBuild.Sdk.Extras": "2.0.46"
  }
}
Olias
  • 401
  • 5
  • 17