0

I have some text, font, and binary files that I need to ship with my app for both Android and iOS. So far what I've been doing is to add one copy per file to each platform project in Visual Studio. So I was wondering whether there could be a way to have a single folder with all the 'raw' assets and get Visual Studio to copy the files for each platform instead, when building the application.

I'd also like to know if the same thing can be done for vector graphics and bitmaps, so that each file is converted to the appropriate size and resolution depending on the target platform when building the app.

I'm asking because after seeing how easy it's to put together a cross-platform application sharing the same UI and base code with Xamarin.Forms, I was thinking that maybe there is a way to do the same thing for raw assets and resources.

rraallvv
  • 2,875
  • 6
  • 30
  • 67

1 Answers1

1

I was thinking that maybe there is a way to do the same thing for raw assets and resources.

You can create a custom NuGet package with MSBuild tasks and a .targets file. In the .target file, you can add all your text, font, and binary files, and then copy those files with MSBuild copy task:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  <PropertyGroup>
    <MySourceFilePath>YourFilesPath</MySourceFilePath>
  </PropertyGroup>

  <ItemGroup>  
    <MySourceFiles Include="$(MySourceFilePath)\*.txt"/>
    <MySourceFiles Include="$(MySourceFilePath)\*.dll"/>  
  </ItemGroup>  

  <Target Name="CopyFiles" AfterTargets="Build">  
    <Copy  
        SourceFiles="@(MySourceFiles)"  
        DestinationFolder="$(ProjectDir)\DestinationFolder"  
    />  
  </Target> 
</Project>

Then Add this .target file into the NuGet package, you can use NuGet Package explorer to create this package:

enter image description here

Then add this package to each project, all your text, font, and binary files will be copy to the project automatically.

Hope this helps.

Community
  • 1
  • 1
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Is there a way to install the local .nupkg file without the Package Manager Console on a Mac? – rraallvv Jan 09 '18 at 14:59
  • On the Mac, you can use nuget CLI to install the local .nupkg. https://learn.microsoft.com/en-us/nuget/tools/cli-ref-install. But you should install Mono 4.4.2 or later. https://learn.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference – Leo Liu Jan 10 '18 at 01:20
  • [I couldn't find a way to do the installation](https://stackoverflow.com/q/48210166/1436359) from the local package. – rraallvv Jan 11 '18 at 15:09