Unity生成的.csproj文件名變動的問題

Unity生成的c#項目名字默認爲Assembly-CSharp.csprojAssembly-CSharp-firstpass.csproj
但是最近看到部分項目名字變成了{projectname}.csproj{projectname}.Plugins.csproj

測試得出,Visual Studio Tools for Unity(VSTU)會自動修改csproj文件名爲{projectname}。查閱文檔也發現ChangeLog有相應的記錄說明和Bug修正。
爲了保證csproj的文件名相同,需要讓所有機器都安裝了VSTU
VS2015之前的版本,可以通過擴展和更新安裝。
VS2017之後的版本,則需要通過Visual Studio Installer安裝。

另外在查文檔的時候,看到VSTU有包含少量可編程方法的說明。

  1. Customize Project Files Created by VSTU
    修改VSTU生成出來的csproj文件

    using System;  
    using System.IO;  
    using System.Linq;  
    using System.Text;  
    using System.Xml.Linq;  
    
    using UnityEngine;  
    using UnityEditor;  
    
    using SyntaxTree.VisualStudio.Unity.Bridge;  
    
    [InitializeOnLoad]  
    public class ProjectFileHook  
    {  
        // necessary for XLinq to save the xml project file in utf8  
        class Utf8StringWriter : StringWriter  
        {  
            public override Encoding Encoding  
            {  
                get { return Encoding.UTF8; }  
            }  
        }  
    
        static ProjectFileHook()  
        {  
            ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>  
            {  
                // parse the document and make some changes  
                var document = XDocument.Parse(content);  
                document.Root.Add(new XComment("FIX ME"));  
    
                // save the changes using the Utf8StringWriter  
                var str = new Utf8StringWriter();  
                document.Save(str);  
    
                return str.ToString();  
            };  
        }  
    }  
  2. Share the Unity Log Callback with VSTU
    共享Visual Studio的輸出到Unity

    using System;  
    
    using UnityEngine;  
    using UnityEditor;  
    
    using SyntaxTree.VisualStudio.Unity.Bridge;  
    
    [InitializeOnLoad]  
    public class LogCallbackHook  
    {  
        static LogCallbackHook()  
        {  
            VisualStudioIntegration.LogCallback += (string condition, string trace, LogType type) =>  
            {  
                // place code that implements your log callback here  
            };  
        }  
    }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章