Open qubitz opened 3 years ago
@qubitz
I was able to get it to work by using an absolute path to the assembly:
t4 -r C:/t4test/bin/Debug/net5.0/t4test.dll ./Test.tt
After that, it complains that it cannot find Custom
, which can be fixed by importing the namespace.
echo "<#@ template language=`"C#`"#>" > Test.tt
echo "<#@ output extension=`".cs`"#>" >> Test.tt
echo "<#@ import namespace=`"Program`" #>" >> Test.tt
echo "<# var t = typeof(Custom); #>" >> Test.tt
Omg, thank you @MoFtZ! That worked for me. I'm starting to understand the cli help now. These are equivalent:
t4 -r C:\t4test\bin\Debug\net5.0\t4test.dll .\Test.tt
t4 -P C:\t4test\bin\Debug\net5.0\ -r t4test.dll .\Test.tt
Also <#@ assembly name="t4test.dll"#>
works with t4 -P C:\t4test\bin\Debug\net5.0\ .\Test.tt
The current help page is a tad vague when it mentions "framework and the include folders" in -r
. Something similar to "specified assembly and include folders" would be preferable.
-r=<assembly> Name or path of an <assembly> reference.
Assemblies will be resolved from the framework
and the include folders
-I=<directory> Search <directory> when resolving file includes
-P=<directory> Search <directory> when resolving assembly
references
I might submit a PR for this if I get some time this week. Thanks again.
Reopening because this definitely seems like a bug that relative assembly paths don't work.
I think this partly might be an artifact of modeling the ResolveAssemblyFile
mechanism in the old VS T4 API. I'd love to modernize the whole thing and get rid of the whole concept of include/search folders.
Offhand, it might be difficult to make sure that assembly references in tt files resolve relative to those files while assembly references on the CLI resolve relative to the working directory.
Ah yes @mhutch, I believe supporting relative assembly paths would be extremely helpful in standardizing setup across different users with the same files. It's also quite intuitive to new users like me who didn't know that t4 templates stand alone from files around them in the same csproj file.
Hi, are there any plans to move forward with this? It'd be extremely useful in maintaining compatibility with .tt files from the .NET Framework era.
Would you feel comfortable with reviewing a PR for this? I'd be happy to contribute.
@davidreis97 absolutely! Pull requests are very welcome. It might be a while till I can review it but I will make time to do so 🙂
I would recommend basing the PR on the build-targets branch rather than master. That's effectively been my dev branch for a while now - there are a bunch of other fixes in addition to the MSBuild targets. I was hoping to get some feedback on the targets (and a better package name) before merging it into master, so it's been sitting on the back burner, but it's pretty much done.
Also, I'm more than happy to review draft PRs, answer questions such as why things are designed/implemented the way they are currently, discuss possible approaches for implementing/fixing things, and so on 🙂
I'm struggling to reference a class that I have defined. I created a step-by-step example of what I'm trying to do:
Resulting output:
What am I doing wrong to reference my
Custom
class? This is probably a common use case, so I suspect that I'm missing something obvious.