microsoft / slow-cheetah

Tooling for XML and JSON file transforms on build from Visual Studio and MSBuild
Other
324 stars 67 forks source link

Transforming an Xamarin Android Asset #56

Open MihaMarkic opened 7 years ago

MihaMarkic commented 7 years ago

Hi guys,

Is it possible to transform an android asset file. Basically it should transform it and put it in the same place (Assets directory or a subdirectory) with the same name.

davilimap commented 7 years ago

If the asset if an XML or JSON file, SlowCheetah should transform it. It will be in the output folder though, not the original folder. I'm not sure if I understood the situation though. Won't putting it in the same place just overwrite the original file?

MihaMarkic commented 7 years ago

"Won't putting it in the same place just overwrite the original file?" I imagine using transformed file for compilation somehow. Or perhaps creating transformed file with different name in the same directory before compilation.

davilimap commented 7 years ago

I'm not too familiar with Xamarin assets, but SlowCheetah outputs files to the output folder. If you need them in a specific folder, you can create a copy task and add it to the project (which can also change the name of the file if that is required). If you need this transformation to occur during a specific time in the build, you can reference the SlowCheetah Build Targets to perform transformations at those times.

horizondave commented 7 years ago

I'm trying to do something similar to this - Xamarin again. I've got an XML file in my PCL project which is an "Embedded Resource" I have code to read from the embedded resource in the PCL project. I have slow cheetah transforms setup on the PCL. I can see that the transformhappens - I see the transformed file in output - but the output transformed file is never "Embedded" in the code that runs on Android or iOS......

I'm assuming that as you specifically allow transforms on files with a build-action of "EmbeddedResource" you also deal with embedding the transformed file instead of the original? In which case, this doesn't seem to work.......Unless there is something else I need to do?

jviau commented 7 years ago

@horizondave slow cheetah does not enable/disable transforms based on msbuild item type, but rather on the contents of the file. If it is valid JSON or XML it will be enabled regardless of what msbuild item type it is. The slowcheetah targets will perform some project specific actions for well-known files, like app.config. Anything beyond that will require custom build targets provided by you.

As for embedded resource, you will need to investigate what Xamarin does with the embedded resources and add msbuild targets to modify the behavior of the SlowCheetah transforms so that xamarin will work with the transformed file and not the original. You can read about the slow cheetah targets here: targets.md.