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

External assemblies referred with macros are not resolved #117

Open
EddieLascu opened this issue Oct 28, 2021 · 2 comments
Open

External assemblies referred with macros are not resolved #117

EddieLascu opened this issue Oct 28, 2021 · 2 comments

Comments

@EddieLascu
Copy link

I need to refer a class declared in a separate assembly. Since my code generation happens as a pre-build event and the classes generated must be added to the build, I need to refer the assembly in the output folder where it is created as part of the build process.

Adding the reference as such:

<#@ assembly name="$(OutDir)\MyOtherAssembly.dll" #>

will result in the following error being logged during build:

System.IO.FileLoadException: The given assembly name or codebase was invalid. (0x80131047)
2> at System.Reflection.AssemblyName.nInit()
2> at System.Reflection.AssemblyName..ctor(String assemblyName)
2> at Mono.TextTemplating.TemplateGenerator.ResolveAssemblyReference(String assemblyReference) in D:\a\t4\t4\Mono.TextTemplating\Mono.TextTemplating\TemplateGenerator.cs:line 221
2> at Mono.TextTemplating.TemplateGenerator.Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost.ResolveAssemblyReference(String assemblyReference) in D:\a\t4\t4\Mono.TextTemplating\Mono.TextTemplating\TemplateGenerator.cs:line 400
2> at Mono.TextTemplating.TemplatingEngine.ProcessReferences(ITextTemplatingEngineHost host, ParsedTemplate pt, TemplateSettings settings) in D:\a\t4\t4\Mono.TextTemplating\Mono.TextTemplating\TemplatingEngine.cs:line 301
2> at Mono.TextTemplating.TemplatingEngine.CompileTemplateInternal(ParsedTemplate pt, String content, ITextTemplatingEngineHost host, TemplateSettings settings) in D:\a\t4\t4\Mono.TextTemplating\Mono.TextTemplating\TemplatingEngine.cs:line 198
2> at Mono.TextTemplating.TemplatingEngine.CompileTemplate(ParsedTemplate pt, String content, ITextTemplatingEngineHost host, TemplateSettings settings) in D:\a\t4\t4\Mono.TextTemplating\Mono.TextTemplating\TemplatingEngine.cs:line 174
2> at Mono.TextTemplating.ToolTemplateGenerator.ProcessTemplate(ParsedTemplate pt, String inputFile, String inputContent, String& outputFile, TemplateSettings settings) in D:\a\t4\t4\dotnet-t4\ToolTemplateGenerator.cs:line 64
2> at Mono.TextTemplating.TextTransform.MainInternal(String[] args) in D:\a\t4\t4\dotnet-t4\TextTransform.cs:line 218
2> at Mono.TextTemplating.TextTransform.Main(String[] args) in D:\a\t4\t4\dotnet-t4\TextTransform.cs:line 42

If I refer the assembly by its fill path, the build process completes fine. That is not an option because my project is also built in an Azure DevOps pipeline where the output folder will obviously be different.

Is there any solution for this?

TIA,
Eddie

@mhutch
Copy link
Member

mhutch commented Oct 5, 2022

You can use the -P command-line option to specify a directory to be searched when resolving assemblies.

AFAIK the $(OutDir) macro isn't a feature of the the T4 engine, it's a feature of the Visual Studio in-process T4 host, which parses resolved certain $() expressions to built-in values from the project system. You would have the same problem executing the templates with Visual Studio's TextTransform.exe CLI tool or MSBuild targets.

I'm open to proposals for solutions to this problem. Perhaps a CLI argument for passing in values to be used in directives using $(name), or allow directives to access session or host parameters.

@safaleval
Copy link

safaleval commented Feb 1, 2023

Good afternoon! It would be great to add a CLI Argument to pass values to be used in directives using $(name), or allow directives to access session or host parameters.

<#@ assembly name="$(TargetDir)$(TargetFileName)" #>
ERROR: Could not find metadata file $(TargetDir)$(TargetFileName).dll"

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

3 participants