Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Tommynator · Sep 30, 2011 at 08:38 AM · editorvisualstudio

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

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 :)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stranger-Games · Sep 30, 2017 at 01:08 AM 0
Share

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.

avatar image Bunny83 Stranger-Games · Sep 30, 2017 at 01:27 AM 0
Share

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

avatar image Stranger-Games Bunny83 · Sep 30, 2017 at 03:32 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to load VS 2013 Pro project from unity? 3 Answers

switching default text editor for Script editing 1 Answer

How to prevent the error "Unable to read the project file ... The attribute "xmlns" in element is unrecognized"? 4 Answers

About the Visual C# Express Editor limitation 6 Answers

Visual Studio 11 (2012) support 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges