<#@ template debug="true" hostspecific="true" language="C#" #> <#@ assembly name="System.Core" #> <#@ assembly Name="EnvDTE" #> <#@ assembly Name="EnvDTE80" #> <#@ assembly Name="VSLangProj" #> <#@ assembly Name="VSLangProj80" #> <#@ import namespace="System.Diagnostics" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.IO" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="System.Text.RegularExpressions" #> <#@ output extension=".txt" #> <# // Initialize dte variable. IServiceProvider hostServiceProvider = (IServiceProvider)Host; dte = (EnvDTE80.DTE2)System.Runtime.InteropServices. Marshal.GetActiveObject("VisualStudio.DTE.12.0"); #> <#+ // Visual Studio entry object. EnvDTE80.DTE2 dte; EnvDTE.ProjectItem GetCurrentProjectItem() { return dte.Solution.FindProjectItem(Host.TemplateFile); } public EnvDTE.Project GetProject(EnvDTE.ProjectItem a_project_item) { object parent = a_project_item.Collection.Parent; if (parent is EnvDTE.Project) return parent as EnvDTE.Project; return GetProject(parent as EnvDTE.ProjectItem); } public void AddReference(EnvDTE.CodeClass a_module_class) { EnvDTE.Project current_project = GetCurrentProjectItem().ContainingProject; EnvDTE.Project reference_project = GetProject(a_module_class.ProjectItem); VSLangProj80.VSProject2 vsproject2 = current_project.Object as VSLangProj80.VSProject2; if (!vsproject2.References.Cast<VSLangProj.Reference>(). Where(el => el.SourceProject != null).Any( el => reference_project.FileName == el.SourceProject.FileName)) { VSLangProj.Reference reference = vsproject2.References.AddProject(reference_project); reference.CopyLocal = false; } } #>
2014-09-03
Add reference to project from Text Template T4
In this example we add project reference taken from EnvDTE.CodeClass.
Subskrybuj:
Komentarze do posta (Atom)
Brak komentarzy:
Prześlij komentarz