Bug 40776 - Unable to add text templates in shared project
Summary: Unable to add text templates in shared project
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: General ()
Version: 4.1.0 (C7)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-04-29 10:44 UTC by Akash Kava
Modified: 2016-04-29 14:26 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Akash Kava 2016-04-29 10:44:45 UTC
Shared Project

It will be nice to have text templates working in Xamarin Forms, I tried modifying shproj file manually to include Text template, but it is of no use. It doesn't seem to work.

I tried to add following markup,

    <Content Include="$(MSBuildThisFileDirectory)Services\ProjectServices.tt">
    <Compile Include="$(MSBuildThisFileDirectory)Services\ProjectServices.cs">

But it does not generate any code, it displays text template correct in shared project.

Current workaround is adding text template in all project, ios, droid. And generate two files, each for each platform. This is fine as of now as same text template is shared between projects by linking the item, but it is not very helpful.
Comment 1 Daniel Cazzulino 2016-04-29 14:26:47 UTC
This is a limitation in Visual Studio Shared Projects feature.

The underlying issue is that shared projects don't have a concept of a Custom Tool like regular projects.

You could simulate something like this by running the text transformations during build, using something like https://www.nuget.org/packages/Clarius.TransformOnBuild/

Not sure if that tool works with shared projects at the moment, but it's open source (at https://github.com/clariuslabs/TransformOnBuild) and PRs are merged pretty quickly by the current maintainer.