Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T4 template doesn't run in "T4DocoptNetHostApp" #75

Closed
atifaziz opened this issue Apr 4, 2021 · 7 comments
Closed

T4 template doesn't run in "T4DocoptNetHostApp" #75

atifaziz opened this issue Apr 4, 2021 · 7 comments

Comments

@atifaziz
Copy link
Collaborator

atifaziz commented Apr 4, 2021

When running the custom tool from within VS, it fails with the following error:

Compiling transformation: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

on line 62 of T4DocoptNet.tt:

var s = new Docopt().GenerateCode(entry.Usage);

It looks like I broke something with PR #59 in spite of testing on my end. 😞

The error message makes sense and while it looks like other people are running into a similar using libraries targeting .NET Standard in T4, I don't see a good solution yet. Even if we manage to find a workaround, I think the following line is going to be troublesome:

<#@ assembly name="$(ProjectDir)$(OutDir)DocoptNet.dll" #>

It means, targets will have to be added and maintained across all supported runtimes, including .NET Framework, .NET Core and .NET 5+, which seems too burdensome.

One option to explore would be to use mono/t4 that's now available as a tool. The integration with VS may not be as sweet though but that could be worked around with some sort of a watcher tool.

@voieducode
Copy link
Member

I have tried adding <#@ assembly name="NetStandard" #> and it seems to fix it at least for .NET Standard

@voieducode
Copy link
Member

voieducode commented Apr 5, 2021

I have initially tried to mitigate the problem by having the path correctly set in the NuGet install.ps1 script. The approach is brittle, but it provides some mitigation for the fresh package installs. Looking at this again, this is not supported anymore in VS 2017+ - I will dig a bit deeper.

@atifaziz
Copy link
Collaborator Author

atifaziz commented Apr 5, 2021

I have tried adding <#@ assembly name="NetStandard" #> and it seems to fix it at least for .NET Standard

I wonder though how that'll sit with a non-SDK-style project that targets .NET Framework.

I do find what's being attempted with T4 is somewhat split & partial given that some code generation happens in the library:

public virtual string GenerateCode()
{
return "// No code for " + Name;
}

Perhaps it's time to look for a fresh approach to the problem? Perhaps something that's done via an MSBuild task? I don't have any proposal off the top of my head at the moment.

@voieducode
Copy link
Member

voieducode commented Apr 5, 2021

Yes I agree. I am a bit disconnected from the .net world. How popular is T4 nowadays?

@atifaziz
Copy link
Collaborator Author

atifaziz commented Apr 5, 2021

How popular is T4 nowadays?

Can't speak for everyone, but I think it's fine if used in a limited way that's not connected to the IDE and works cross-platform via mono/t4. I think what people love about T4 is the quick inner dev loop with saving and seeing the generated code/text update almost immediately. I wish dotnet watch could make up for that, but I think it's somewhat limited to web development scenarios for now. I don't have the cycles to explore the options with MS Build because I'd rather channel my energies on exploring the source generator method in PR #77. If I get lightbulb moment for T4 part or a replacement, I'll drop a PR (no promises).

@voieducode
Copy link
Member

Yes I would rather invest in the source code generator as well.

@atifaziz
Copy link
Collaborator Author

atifaziz commented Dec 4, 2021

Closing since T4 support was removed in PR #136.

@atifaziz atifaziz closed this as completed Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants