How to Create/Generate Project File Programmatically in .Net?
There are situations where the source files are generated dynamically either through templates or codeDOM, therefore we need a mechanism to package those source files in a project. .Net allows to generate project files dynamically using the Microsoft.Build.Construction. Generating Project File Dynamically In this post lets see with an example how we can generate csproj file, add the source files and references dynamically into the csproj file. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 using Microsoft.Build.Construction ; namespace OnTheFlyCompilation { class Program { static void Main ( string [] args) { var root = ProjectRootElement.Create(); var group = root.AddPropertyGroup(); group .AddProperty( "Configuration" , "Release" ); group .AddProperty( "Platform" , "x64" ); // referen...