Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
8
Question by DavidB · Oct 01, 2010 at 03:19 PM · visualstudiorecompile

Is there a way to stop Unity3 from regenerating the Visual Studio Project file on every compile?

Everytime I make script changes and flip back to Vis Studio 2010, it asks me if I'd like to reload the project, and I have to re-convert every time (to 2010).

Is there a way to stop Unity from constantly regenerating the project file even though no scripts have been added/removed?

Thank you

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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by killroy · Jul 12, 2011 at 09:33 PM

Very annoying.

I use this small script that I put into Assets/Editor

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 using System.IO;
 using System.Text.RegularExpressions;
 
 class UpgradeVSProject : AssetPostprocessor 
 {
     private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) 
     {
         Debug.Log("Reimported Asset");
 
         string currentDir = Directory.GetCurrentDirectory();        
         string[] slnFile = Directory.GetFiles(currentDir, "*.sln");
         string[] csprojFile = Directory.GetFiles(currentDir, "*.csproj");
         
         if(slnFile.Length > 0 && csprojFile.Length > 0)
         {
             ReplaceInFile(slnFile[0], "Format Version 10.00", "Format Version 11.00");
             ReplaceInFile(csprojFile[0], "ToolsVersion=\"3.5\"", "ToolsVersion=\"4.0\"");
             ReplaceInFile(csprojFile[0], "<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>", "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>");
             Debug.Log("Upgraded to Visual Studio 2010 Solution");
         }
     }
 
     static private void ReplaceInFile(string filePath, string searchText, string replaceText)
     {
         StreamReader reader = new StreamReader(filePath);
         string content = reader.ReadToEnd();
         reader.Close();
 
         content = Regex.Replace(content, searchText, replaceText);
 
         StreamWriter writer = new StreamWriter(filePath);
         writer.Write(content);
         writer.Close();
     }
 }

 

It waits until Unity is finished with compilation and asset import. At this point VS files should already be generated, so it simply takes the solution and project file and replaces a few strings so that VS2010 doesn't complain. I tested this only with a basic project and on Visual C# Express 2010. It's not the best workaround, but I hope it helps.

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 mweldon · Sep 17, 2011 at 09:59 PM 0
Share

This works for me. Thanks for posting it.

avatar image mweldon · Sep 18, 2011 at 06:25 AM 0
Share

Although I had to modify it to loop through all the slnFile and csprojFile ins$$anonymous$$d of just doing the 0th one of each.

avatar image killroy · Sep 18, 2011 at 10:54 AM 0
Share

Yeah, this is needed with the latest Unity 3.4 as it generates several solution and project files. I'm glad this works for you.

avatar image
1

Answer by Noise crime · Jul 10, 2011 at 01:26 AM

Its annoying isn't it.

The workaround i've found is ...

  1. Sync the unity project with VS2010.

  2. Open VS2010, let it convert the project file.

  3. In VS2010, select the solution, then 'save solution as' and append 'VS2010' to the file name.

  4. Select the project in the solution pane and rename it, appending 'VS2010'.

  5. Do a 'save all'.

  6. Quit VS.

  7. In your project folder delete the old none renamed sln, which should leave you with just the renamed sln and csproj files.

You can now open the project via the sln file. Editing the files in vs2010 or unity editor should no longer force a re-convert. However you will have to repeat this process everytime you add a new script via Unity, but not if you add one via VS2010.

Comment
Add comment · 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
1

Answer by michiel_frankfort · Jan 19, 2012 at 12:12 PM

Thanks Killroy for your help, your script was very usefull!

But there it does not entirely convert the project and I had to adjust your script to make it run properly. Besides, after I got it to work, i get a reload prompt each time I switchback to VisualStudio. So I created a little version-check to the script, that only performs the conversion when versions missmatch. It makes life a whole lot easier and thats why I want to share this super-solid update with you:"


 using UnityEngine;

using System.Collections; using UnityEditor; using System.IO; using System.Text.RegularExpressions;

class UpgradeVSProject : AssetPostprocessor { private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { string currentDir = Directory.GetCurrentDirectory();
string[] slnFile = Directory.GetFiles(currentDir, ".sln"); string[] csprojFile = Directory.GetFiles(currentDir, ".csproj");

    bool hasChanged = false;
    if (slnFile != null)
    {
        for (int i = 0; i < slnFile.Length; i++)
        {
            if (ReplaceInFile(slnFile[i], "Format Version 10.00", "Format Version 11.00"))
                hasChanged = true;
        }
    }

    if (csprojFile != null)
    {
        for (int i = 0; i < csprojFile.Length; i++)
        {
            if (ReplaceInFile(csprojFile[i], "ToolsVersion=\"3.5\"", "ToolsVersion=\"4.0\""))
                hasChanged = true;

            if (ReplaceInFile(csprojFile[i], "<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>", "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>"))
                hasChanged = true;
        }
    }

    if (hasChanged)
    {
        Debug.LogWarning("Project is now upgraded to Visual Studio 2010 Solution!");
    }
    else
    {
        Debug.Log("Project-version has not changed...");
    }
 }

 static private bool ReplaceInFile(string filePath, string searchText, string replaceText)
 {
     StreamReader reader = new StreamReader(filePath);
     string content = reader.ReadToEnd();
     reader.Close();

     if (content.IndexOf(searchText) != -1)
     {
        content = Regex.Replace(content, searchText, replaceText);
         StreamWriter writer = new StreamWriter(filePath);
         writer.Write(content);
         writer.Close();

         return true;
     }

     return false;
 }

}

Comment
Add comment · Show 2 · 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 killroy · Jan 22, 2012 at 07:16 PM 0
Share

Hey $$anonymous$$ichiel,

That is great! Thanks for the update. Yes, reload prompt is annoying, because the sln is regenerated every time you do something in Unity. This version check is a great idea!

avatar image ABerlemont · Nov 24, 2015 at 12:29 AM 0
Share

Hey michiel_frankfort you should fix the formatting of your answer :). Thanks!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating .unityPackage from within Visual Studio 1 Answer

Using Unity 3.4 with Visual Studio 2008 & 2010 problem. 0 Answers

WinRTBridge.winmd exception 1 Answer

Get the Data from a Serial Port, Work in VB but in Unity Dont. 2 Answers

Compiling C# in Visual Studio? 1 Answer


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