Reputation: 5449
Hi I am just starting out with T4 templates and I need to generate a javascript file based on the actions in my controller.
I got the code all figured out forgetting the controllers and actions my only problem is that I am getting this error in the T4 template file and I do not understand it:
Compiling transformation: A namespace cannot directly contain members such as fields or methods
This is my code:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="eConnect.WebApi.Helpers.T4.ControllerDetails" #>
<#@ import namespace="System.Web.Http;"#>
<#@ output extension=".js" #>
define(['services/logger',
'services/jsonDataService',
'services/config',
'services/cachingService'],
function (logger, jsonDataService, config, cache) {
var dataService = { };
return dataService;
});
<#
var controllers = ControllersInfo.GetControllers();
foreach(var controller in controllers) {
Dictionary<string, ParameterInfo[]> actions = ControllersInfo.GetAllCustomActionsInController(controller, new HttpGetAttribute());
}
#>
There is also an external class that gets the controllers and actions but I do not think it's necesary for the current problem.
What am I doing wrong?
Upvotes: 6
Views: 4017
Reputation: 11577
You probably have this figured out by now but:
<#@ import namespace="System.Web.Http;"#>
Note the ';'
Instead write:
<#@ import namespace="System.Web.Http"#>
Upvotes: 6