This is my first question about StackOverflow, so Hi :)
Is it possible to load an assembly named Assembly using Assembly.Load () in the t4 template? I would like to use it to get all types with the ServiceContract attribute in the loaded assembly.
var loadedAssembly = Assembly.Load(assemblyName);
var types = from type in loadedAssembly.GetTypes()
where Attribute.IsDefined(type, typeof(ServiceContractAttribute))select type;
The desired assembly is referenced in the project where my template is located. I realized that
<#@ assembly name="$(TargetDir)\DesiredAssemblyName.dll" #>
var loadedAssembly = Assembly.GetAssembly(typeof(SomeType));
works, but it doesn't seem like a good solution. Also, I want this template to be converted after the build, and when I add the following lines to .csproj
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\
TextTemplating\v10.0\Microsoft.TextTemplating.targets"/>
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<ItemGroup>
<T4ReferencePath Include="..\Onii.Vespa.AppServer\"/>
</ItemGroup>
with Assembly.GetAssembly also does not work. Thank you for all the suggestions.
source
share