none
T4 Assembly Reference Issue, Local path works, references do not RRS feed

  • Question

  • I have a T4 template that I have created to use FxCop's Introspection engine however, my reference to it only works when I use an abolute path on my local machine.

    <#@

     

    assembly name="C:\Program Files\Microsoft FxCop 1.35\FxCopSdk.dll" #>

    <#@

     

    assembly name="C:\Program Files\Microsoft FxCop 1.35\Microsoft.Cci.dll" #>

    When I change these to:

    <#@

     

    assembly name="FxCopSdk.dll" #>

    <#@

     

    assembly name="Microsoft.Cci.dll" #>

    It does not load because it is executing in a temp directory.  I understand this.  However, if I had a Reference path in the project properties or I add a project reference to the DLL in my class library, throws the same exceptiong.

    According to Oleg's blog, it is supposed to look at the abolute path, then GAC, then project reference paths, then project references.  It does not appear to be doing this.

    I am using VS2010

    Tuesday, June 22, 2010 2:07 PM

Answers

  • David,

    In Visual Studio 2010, T4 no longer relies on project references when resolving assembly references. Instead, you can use environment variables (%ProgramFiles%) or Visual Studio macros (%(SolutionDir)). Ideally you would reference assembly by name, from GAC. In this particular case, you could use %VS100COMNTOOLS% to construct a relative path to Microsoft.Cci.dll located in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies on my computer.


    Oleg
    Tuesday, June 22, 2010 3:48 PM

All replies

  • David,

    In Visual Studio 2010, T4 no longer relies on project references when resolving assembly references. Instead, you can use environment variables (%ProgramFiles%) or Visual Studio macros (%(SolutionDir)). Ideally you would reference assembly by name, from GAC. In this particular case, you could use %VS100COMNTOOLS% to construct a relative path to Microsoft.Cci.dll located in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies on my computer.


    Oleg
    Tuesday, June 22, 2010 3:48 PM
  • To be clear you can just use the same type of variables that you would normally use in a Post-Build or Pre-Build event in MsBuild in your solution file.

    <#@ assembly name="$(TargetDir)DataModel.dll" #>
    <#@ assembly name="$(TargetDir)Common.dll" #>

    Thanks for the direction Oleg, saved me a lot of headache.

    ~Matt

    Wednesday, March 7, 2012 9:44 PM