- Home /
Configuration of Visual Studio csproj
Is there any way to customize the generation of the .csproj file for VisualStudio? I need to customize my project configuration, but Unity is always rewriting the file from scratch and overwriting my local changes.
It would also help me if the internal compile event would be exposed to an editor class, such that I could automatically build my own .csproj file on each compilation (or any other project/hierarchy change event).
Any ideas about that? Googled a bit but couldn't find any good solution.
Thomas
Answer by Tommynator · Mar 02, 2012 at 09:45 AM
It's been a while but I thought answering this post might help some people, who need more control over the visual studio project. To create a vs proj is not big deal, but the key point is: How to automatically generate it when you remove or create files in unity?
Answer: Hook into the OnPostProcessAllAssets Editor function of the AssetProcessor class.
class PostBuildEventController : AssetPostprocessor
{
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
//here call your .csproj generation code
}
}
After that I just parse the Asset directory like:
var di = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "Assets"));
FileInfo[] fis = di.GetFiles("*.cs", SearchOption.AllDirectories);
and construct a .csproj file that I include in my custom solution. That way I have full control over all project settings, included file types, error/warnings settings etc.
If somebody needs more details, just ask :)
Thanks, that's very useful. If you don't $$anonymous$$d, would you tell us which library did you use to generate the .csproj file? I can't use $$anonymous$$icrosoft.Build because it relies on .net 4.0, but unity editor uses .net 3.5. Thanks for advance.
Note that the ".csproj" is actually ignored by Unity. It's only used to tell your code editor (Visual Studio / $$anonymous$$onoDevelop / ...) which files and assemblies belong to the project. Unity does invoke the compiler manually for most platforms (at least when $$anonymous$$ono is used).
If you want to modify certain compiler parameters you can use an rsp file, however if can only adjust certain compiler options
Thanks. I need to create a manual csproj for organization purposes when editing the code. I am not sure if unity uses a certain library for generating csproj or custom code. If Unity uses a library I would use it to avoid importing more libraries into the unity project, but I am not sure what Unity uses under the hood.
Your answer
Follow this Question
Related Questions
How to load VS 2013 Pro project from unity? 3 Answers
switching default text editor for Script editing 1 Answer
About the Visual C# Express Editor limitation 6 Answers
Visual Studio 11 (2012) support 3 Answers