Reputation: 31
I'm using T4 templates (run-time generated) to generate few .cs files for my project (controller, entity and views) that needs to be created dynamically by my controller's action, which pass specific data to these templates.
It's the way I generate them in my action:
CustomEntity entity = new CustomEntity(entityName, propertyMap);
String entityContent = entity.TransformText();
System.IO.File.WriteAllText(Server.MapPath("~") + "\\Models\\" + entityName + ".cs", entityContent);
CustomEntityController controller = new CustomEntityController(entityName);
String controllerContent = controller.TransformText();
System.IO.File.WriteAllText(Server.MapPath("~") + "\\Controllers\\" + entityName + "Controller.cs", controllerContent);
They are generated properly, but however they are not inluded in my project, so I can't use them in my project anyway. Only right-button click on the file and "Include in project" solve this issue, but I need them accessible in my project automatically.
How can I solve this problem?
Upvotes: 2
Views: 828
Reputation: 2999
You can include dynamically-generated .cs-files in to Visual Studio project with recursive wildcard-inclusion as mentioned in this answer. This can be done with manually editing the csproj-file.
Syntax is following (check proper paths in your case):
<ItemGroup>
<Compile Include="Models\**\*.cs" />
<Compile Include="Controllers\**\*.cs" />
</ItemGroup>
Upvotes: 1