locked
T4 Inherits custom assembly locking in vs2010 RRS feed

  • Question

  • Hi, I am trying to build my non-trivial code in a set of classes (for compile time checking) then in the same project have .tt files that inherit that file. using

    <#@

     

    template debug="false" hostspecific="true" language="C#" inherits="MyNamespace.MyClass"#>

    <#@

     

    assembly name = "C:\MyPath\MyDll.dll" #>

    This works fine until I need to recompile the dll, at this point I get build problems "Unable to copy file <objSrc> to <binDest>. The process cannot access the file <binDest> because it is being used by another process

    Now I know that this is VS caching the dll, however the question is how to I prevent it. MSDN does state that you can use this inherits method however if you can't disable the caching this is fairly useless isn't it? It would make it totally impractal to have to keep closing vs each time you make a change and need to test.

    I have found an article http://blogs.msdn.com/b/garethj/archive/2006/06/05/t4caching.aspx which explains how to disable this however I don't think this works for vs2010. I am running vs2010 on a 64 bit Win7 system. I have tried both adding CacheAssemblies to both

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\TextTemplating (which already existed)
    and
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\TextTemplating (which I had to create)

    and have tried as both a string of "false" as well as a dword of 0 and still no luck.

    In testing I run my script with the includes once, then try to compile assembly (fail), then try running a basic .tt file with just "hello" in it, then try compile again and each time this second attempt fails

    Could someone try and confirm this isn't working for them also or let me know what I might be doing wrong? Thanks for any help!

    Tuesday, May 25, 2010 3:50 PM

Answers

All replies

  • Hi Brett,

    Maybe You could try T4Toolbox plugin from Oleg Sych and use the "volatile assembly" feature described here:

    http://www.georgemk.com/2009/12/t4-template-reference-to-frequently.html

    Tuesday, May 25, 2010 4:12 PM
  • I've never been able to make the CacheAssemblies option work from the standpoint of assembly locking. I think the problem is that T4 checks this option only in the beginning of template transformation, so the referenced assemblies remain locked until the next transformation recycles the appdomain.

    As @Fedi24 pointed out, George Mathew contributed a custom directive processor called "VolatileAssembly" to T4Toolbox, which should help you to get around this problem.


    Oleg
    Tuesday, May 25, 2010 4:31 PM
  • Hi Oleg,

    I've asked a question on your blog. Goes like this:

    I've tried to implement your volatile assembly directive and it works (partly). It's mainly because our Assembly uses other Assemblies that are not copied. The Assembly in the directive can therefore not be loaded.

    I've also downloaded the source and tried to implement my own but the code for VS2010 differs greatly from the previous versions.

    Can you help me?

    Regards
    Paul Sinnema


    Take a look at my blog: http://paul.sinnema.ch
    Tuesday, June 29, 2010 4:56 PM
  • Paul, I would guess that in this case you would include all the assemblies as directives (either assembly or VolatileAssembly as appropriate)? Doesn't this work
    • Proposed as answer by PaulSinnema Wednesday, June 30, 2010 11:34 AM
    Wednesday, June 30, 2010 8:42 AM
  • Paul,

    It's been a while since I looked at this code. If I remember correctly, it didn't support custom assemblies that reference other custom assemblies. Perhaps George Mathew, who wrote the VolatileDirective processor, could suggest how to extend it.


    Oleg
    Wednesday, June 30, 2010 11:18 AM
  • Paul, I would guess that in this case you would include all the assemblies as directives (either assembly or VolatileAssembly as appropriate)? Doesn't this work

    Hi Brett,

    That seems like a sensible solution. I'll try it.

    Regards
    Paul Sinnema


    Take a look at my blog: http://paul.sinnema.ch
    Wednesday, June 30, 2010 11:33 AM
  • Paul,

    It's been a while since I looked at this code. If I remember correctly, it didn't support custom assemblies that reference other custom assemblies. Perhaps George Mathew, who wrote the VolatileDirective processor, could suggest how to extend it.


    Oleg

    Hi Oleg,

    Thanks for replying. If Brett's Solution doesn't work, I will contact George.

    Regards
    Paul Sinnema.


    Take a look at my blog: http://paul.sinnema.ch
    Wednesday, June 30, 2010 11:34 AM
  • Paul, I would guess that in this case you would include all the assemblies as directives (either assembly or VolatileAssembly as appropriate)? Doesn't this work

    Brett, Oleg,

    Thanks guys for this super solution. Finally our Assemblies are no longer locked. That will help boost turn-around-time in Development. Thanks again.

    Regards;
    Paul Sinnema 


    Take a look at my blog: http://paul.sinnema.ch
    Wednesday, June 30, 2010 11:59 AM