Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Mono.TextTemplating.Build/Mono.TextTemplating.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<ItemGroup>
<None Include="readme.md" Pack="true" PackagePath="\" />
<ProjectReference Include="..\Mono.TextTemplating\Mono.TextTemplating.csproj" PrivateAssets="all" />
<ProjectReference Include="..\Mono.TextTemplating.Roslyn\Mono.TextTemplating.Roslyn.csproj" PrivateAssets="all" />
<PackageReference Include="MessagePackAnalyzer" Version="2.5.129" PrivateAssets="all" />
<PackageReference Include="MessagePack" Version="2.5.129" PrivateAssets="all" />
<!-- intentionally downlevel these so they can be loaded in older VS versions -->
Expand Down
2 changes: 2 additions & 0 deletions Mono.TextTemplating.Build/T4.BuildTools.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<UseLegacyT4Preprocessing Condition="'$(UseLegacyT4Preprocessing)'==''">False</UseLegacyT4Preprocessing>
<TransformOnBuild Condition="'$(TransformOnBuild)'==''">False</TransformOnBuild>
<TransformOutOfDateOnly Condition="$(TransformOutOfDateOnly)==''">true</TransformOutOfDateOnly>
<T4UseInProcessCompiler Condition="'$(T4UseInProcessCompiler)'==''">false</T4UseInProcessCompiler>
<!-- legacy compat -->
<T4DefaultNamespace Condition="'$(T4DefaultNamespace)'==''">$(PreprocessTemplateDefaultNamespace)</T4DefaultNamespace>
<T4DefaultNamespace Condition="'$(T4DefaultNamespace)'==''">$(RootNamespace)</T4DefaultNamespace>
Expand Down Expand Up @@ -92,6 +93,7 @@
IntermediateDirectory="$(_T4IntermediateTemplateOutputDir)"
TransformOutOfDateOnly="$(TransformOutOfDateOnly)"
PreprocessTargetRuntimeIdentifier="$(TargetFrameworkIdentifier)"
UseInProcessCompiler="$(T4UseInProcessCompiler)"
>
<Output TaskParameter="TransformTemplateOutput" ItemName="GeneratedTemplates" />
<Output TaskParameter="PreprocessedTemplateOutput" ItemName="PreprocessedTemplates" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
"description": "Place preprocessed templates beside the templates instead of dynamically injecting them into the build.",
"type": "bool"
},
"T4UseInProcessCompiler": {
"description": "Use the in-process Roslyn compiler for T4 templates, enabling modern C# language features even when running under Visual Studio's .NET Framework MSBuild host.",
"type": "bool",
"defaultValue": "false"
},
"T4Arguments": {
"description": "Used to pass arguments when invoking on the CLI. This is a semicolon-separated list and uses the same format as encoded `T4Argument` items: `name=value`, `directive!name!value` or `processor!directive!name!value`.",
"isList": true
Expand Down
2 changes: 2 additions & 0 deletions Mono.TextTemplating.Build/TemplateBuildState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class TemplateBuildState
public List<Parameter> Parameters { get; set; }
[Key(10)]
public string PreprocessTargetRuntimeIdentifier { get; set; }
[Key(11)]
public bool UseInProcessCompiler { get; set; }

internal (List<TransformTemplate> transforms, List<PreprocessedTemplate> preprocessed) GetStaleAndNewTemplates (
TemplateBuildState previousBuildState, bool preprocessOnly, Func<string, DateTime?> getFileWriteTime, TaskLoggingHelper logger)
Expand Down
4 changes: 3 additions & 1 deletion Mono.TextTemplating.Build/TextTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public TextTransform () : base (Messages.ResourceManager) { }
public bool PreprocessOnly { get; set; }
public bool UseLegacyPreprocessingMode { get; set; }
public bool TransformOutOfDateOnly { get; set; }
public bool UseInProcessCompiler { get; set; }

public string PreprocessTargetRuntimeIdentifier { get; set; }

Expand Down Expand Up @@ -74,7 +75,8 @@ public override bool Execute ()
var buildState = new TemplateBuildState {
IntermediateDirectory = IntermediateDirectory,
DefaultNamespace = DefaultNamespace,
PreprocessTargetRuntimeIdentifier = PreprocessTargetRuntimeIdentifier
PreprocessTargetRuntimeIdentifier = PreprocessTargetRuntimeIdentifier,
UseInProcessCompiler = UseInProcessCompiler
};

success &= AddParameters (buildState);
Expand Down
5 changes: 5 additions & 0 deletions Mono.TextTemplating.Build/TextTransformProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Microsoft.Build.Utilities;
using Microsoft.VisualStudio.TextTemplating;

using Mono.TextTemplating;

namespace Mono.TextTemplating.Build
{
static class TextTransformProcessor
Expand Down Expand Up @@ -191,6 +193,9 @@ static void WriteOutput (MSBuildTemplateGenerator generator, string outputFile,
static MSBuildTemplateGenerator CreateGenerator (TemplateBuildState buildState)
{
var generator = new MSBuildTemplateGenerator ();
if (buildState.UseInProcessCompiler) {
generator.UseInProcessCompiler ();
}
if (buildState.ReferencePaths != null) {
generator.ReferencePaths.AddRange (buildState.ReferencePaths);
}
Expand Down