efcore
efcore copied to clipboard
Run the string resources T4 files on build
Does our T4 template run outside of VS already? /cc @bricelam
@roji Our T4 templates currently require VS.
I think I already have an MQ issue to clean these up and make them runnable outside of VS. Not sure I’d want them to run on build, but there’s been some work in mono/t4 on an MSBuild task to do this.
I worked on something like that to run the my own t4 files on build in Visual Studio with an msbuild task that invokes dotnet-t4
from mono/t4 without using their msbuild task (as I am not aware on the status of that task on the ability to use it cross platform unlike with it using dotnet-t4
.
But then again, I could argue this: I think that dotnet ef scaffold
should be the only places where the templates are used (provided the templates are needed for scaffolding).
@AraHaan this is about string resx that generate string resources and logging code, so internal EF stuff, not scaffolding.
Ah, I see. Then yeah an msbuild task like this would work too:
<PropertyGroup>
<T4OutputDirectory>[the folder that efcore outputs them currently]</T4OutputDirectory>
</PropertyGroup>
<Target
BeforeTargets="CoreCompile"
Name="T4TransformXPlat"
Condition="[only generate the code files only when those files do not exist]">
<Message Importance="high" Text="Running t4 text transforms." />
<Exec
Command="dotnet t4 -o - -p:RootNamespace=$(RootNamespace) -p:OutputDirectory="$(T4OutputDirectory)" -p:ProjectName=$(MSBuildProjectName) < "$(MSBuildProjectDirectory)/[the t4 file paths here]""
StandardErrorImportance="low"
StandardOutputImportance="low" />
<ItemGroup>
<Compile Include="$(T4OutputDirectory)/[the generated files here]" />
</ItemGroup>
<Message Importance="high" Text="Done outputting files." />
</Target>
This should work for basic templates that write file(s) directly, yes my t4 file takes in RootNamespace
, and OutputDirectory
so it would know where to save the files it needs to write.
@AraHaan see the note above about our templates currently requiring VS (we plan to remove that requirement).