0

Given the following tt macro:

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".xml" #>
<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="System.Reflection" #>
<#
AssemblyInfoHelper assemblyInfo = new AssemblyInfoHelper(Assembly.LoadFrom(@"H:\My Projects\TestApp\bin\Windows Phone\Debug\TestApp.dll"));
#>
<?xml version="1.0" encoding="utf-8"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
...
</Deployment>

... I'd like to Load the assembly using the content of $(TargetPath) instead of hardcoding the assembly's full path... Is that possible?

Any help is really appreciated :-)

Thanks j3d

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
j3d
  • 9,492
  • 22
  • 88
  • 172
  • There are a number of workarounds/example discussed here: http://weblogs.asp.net/lhunt/archive/2010/05/04/t4-template-error-assembly-directive-cannot-locate-referenced-assembly-in-visual-studio-2010-project.aspx ... think you need to use something similar to "$(TargetDir)MyAssembly.dll" – Colin Smith Aug 11 '12 at 19:51
  • <#@ assembly name="$(TargetPath)" #> already contains the full path of the assembly in need to reference... What I'm looking for is a way to replace the hardcoded path in the code below the directives: Assembly.LoadFrom(@"H:\My Projects\TestApp\bin\Windows Phone\Debug\TestApp.dll") should be something like Assembly.LoadFrom("$(TargetPath)") - of course, this doesn't work :-( – j3d Aug 11 '12 at 22:30
  • Perhaps use VCConfiguration.Evaluate .... http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vcconfiguration.evaluate.aspx .... http://stackoverflow.com/questions/8477011/how-to-get-expanded-path-from-envdte-vcprojectengine .....or access the DTE Interface ..... http://stackoverflow.com/questions/3408159/using-types-in-a-t4-template-that-exist-in-the-same-project-as-the-template – Colin Smith Aug 11 '12 at 22:43

1 Answers1

0

If you've already loaded the assembly with an assembly directive using the $(TargetPath) syntax, then you can pick a type from the assembly, do a typeof(Foo) and get into the reflection graph from there instead of referencing the path again.

GarethJ
  • 6,496
  • 32
  • 42
  • This was my first try... but I always got the following error: Error 4 Running transformation: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Reflection.Assembly.GetAssembly(Type type) at Microsoft.VisualStudio.TextTemplatingCA318D3CFBFC9BADB1A4FE595511DFB9.GeneratedTextTransformation.TransformText() at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result) 1 1 – j3d Aug 13 '12 at 20:21