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  
            };  
        }  
    }  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值