bennor / AutoT4

A zero-configuration extension for Visual Studio 2012+ which automatically runs your T4 templates at build time.
MIT License
11 stars 14 forks source link

Using template as link in multiple projects, get 'This document is opened by another project.' #15

Closed sparticus1701 closed 8 years ago

sparticus1701 commented 8 years ago

I manage an internal framework which is currently has multiple projects. The version for the projects come from a single solution item called CommonAssemblyInfo.cs, which has been added as a link to each project.

I would like to add a build number to the version by using a .tt file in the same way. It would be a solution item which is added as a link in each project. I'm using AutoT4 to generate the .cs file from the .tt file at build time.

It seems to be working just fine except when I do a build I get an pop-up error "This document is opened by another project." I would guess that AutoT4 is trying to execute the template in each project that is using it, and then having a collision.

Can you tell me if that is the case and if there's anyway around it?

Using VS2015

sparticus1701 commented 8 years ago

Looking at the AutoT4Package.RunTemplates() method, if the generated list has path information can .Distinct() be added?

sparticus1701 commented 8 years ago

Found the error was not thrown from AutoT4; I found a way to do it with include statement.

bennor commented 8 years ago

Glad you were able to sort it out. You sure the lack of a distinct on the templates is not a problem? I'll have a look into it when I get time. They don't run in parallel, so at worst it should mean that it runs the same template over and over.

sparticus1701 commented 8 years ago

In this particular case running Distinct may not do anything, since the collection is a set of objects that contain info about the context/project in addition to the template.

bennor commented 8 years ago

Okay. Will ignore for now then.

JustasSasnauskas commented 7 years ago

Can you explain more detail what was done there to make message box "This document is opened by another project." go away? I also using same solution. Adding same tt file as a link to multiple project expecting it to generate same version number in all solution project. But as far as I add tt to two project or more, message box "This document is opened by another project." appears.

sparticus1701 commented 7 years ago

Rather than each project linking to the same .tt file, each project has it's own .tt file containing a line like this: <#@ include file="..\ZExtra\CommonAssemblyInfo.ttinclude"#>

JustasSasnauskas commented 7 years ago

Thank you! It works like a charm.