示例#1
0
        /// <summary>
        /// Callback from AssetPostprocessor which is called after CSProj file(s) are generated.
        /// </summary>
        public static void OnGeneratedCSProjectFiles()
        {
            if (!UnityVSSupport.IsUnityVSEnabled())
            {
                return;
            }

            try
            {
                var projectDir   = Directory.GetCurrentDirectory();
                var projectFiles = Directory.GetFiles(projectDir, string.Format("*{0}", SolutionSynchronizer.GetProjectExtension(ScriptingLanguage.CSharp)), SearchOption.TopDirectoryOnly);
                foreach (string projectFile in projectFiles)
                {
                    var file = projectFile.Substring(projectDir.Length + 1);
                    ReplacePathsInProjectFile(file, projectDir);
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogWarning("Post processing of CS project files failed, reason: " + e.Message);
            }
        }
        private string ProjectText(MonoIsland island, SolutionSynchronizer.Mode mode, string allAssetsProject)
        {
            StringBuilder stringBuilder = new StringBuilder(this.ProjectHeader(island));
            List <string> list          = new List <string>();
            List <Match>  list2         = new List <Match>();

            string[] files = island._files;
            for (int i = 0; i < files.Length; i++)
            {
                string text  = files[i];
                string b     = Path.GetExtension(text).ToLower();
                string text2 = (!Path.IsPathRooted(text)) ? Path.Combine(this._projectDirectory, text) : text;
                if (".dll" != b)
                {
                    string arg = "Compile";
                    stringBuilder.AppendFormat("     <{0} Include=\"{1}\" />{2}", arg, this.EscapedRelativePathFor(text2), SolutionSynchronizer.WindowsNewline);
                }
                else
                {
                    list.Add(text2);
                }
            }
            stringBuilder.Append(allAssetsProject);
            foreach (string current in list.Union(island._references))
            {
                if (!current.EndsWith("/UnityEditor.dll") && !current.EndsWith("/UnityEngine.dll") && !current.EndsWith("\\UnityEditor.dll") && !current.EndsWith("\\UnityEngine.dll"))
                {
                    Match match = SolutionSynchronizer.scriptReferenceExpression.Match(current);
                    if (match.Success && (mode == SolutionSynchronizer.Mode.UnityScriptAsUnityProj || (int)Enum.Parse(typeof(ScriptingLanguage), match.Groups["language"].Value, true) == 2))
                    {
                        list2.Add(match);
                    }
                    else
                    {
                        string text3 = (!Path.IsPathRooted(current)) ? Path.Combine(this._projectDirectory, current) : current;
                        if (AssemblyHelper.IsManagedAssembly(text3))
                        {
                            if (!AssemblyHelper.IsInternalAssembly(text3))
                            {
                                text3 = text3.Replace("\\", "/");
                                text3 = text3.Replace("\\\\", "/");
                                stringBuilder.AppendFormat(" <Reference Include=\"{0}\">{1}", Path.GetFileNameWithoutExtension(text3), SolutionSynchronizer.WindowsNewline);
                                stringBuilder.AppendFormat(" <HintPath>{0}</HintPath>{1}", text3, SolutionSynchronizer.WindowsNewline);
                                stringBuilder.AppendFormat(" </Reference>{0}", SolutionSynchronizer.WindowsNewline);
                            }
                        }
                    }
                }
            }
            if (0 < list2.Count)
            {
                stringBuilder.AppendLine("  </ItemGroup>");
                stringBuilder.AppendLine("  <ItemGroup>");
                foreach (Match current2 in list2)
                {
                    string value = current2.Groups["project"].Value;
                    stringBuilder.AppendFormat("    <ProjectReference Include=\"{0}{1}\">{2}", value, SolutionSynchronizer.GetProjectExtension((ScriptingLanguage)((int)Enum.Parse(typeof(ScriptingLanguage), current2.Groups["language"].Value, true))), SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendFormat("      <Project>{{{0}}}</Project>", this.ProjectGuid(Path.Combine("Temp", current2.Groups["project"].Value + ".dll")), SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendFormat("      <Name>{0}</Name>", value, SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendLine("    </ProjectReference>");
                }
            }
            stringBuilder.Append(this.ProjectFooter(island));
            return(stringBuilder.ToString());
        }
 public static void OnGeneratedCSProjectFiles()
 {
     if (UnityVSSupport.IsUnityVSEnabled())
     {
         try
         {
             string   currentDirectory = Directory.GetCurrentDirectory();
             string[] files            = Directory.GetFiles(currentDirectory, string.Format("*{0}", SolutionSynchronizer.GetProjectExtension(ScriptingLanguage.CSharp)), SearchOption.TopDirectoryOnly);
             string[] array            = files;
             for (int i = 0; i < array.Length; i++)
             {
                 string text        = array[i];
                 string projectFile = text.Substring(currentDirectory.Length + 1);
                 SolutionPostProcessor.ReplacePathsInProjectFile(projectFile, currentDirectory);
             }
         }
         catch (Exception ex)
         {
             Debug.LogWarning("Post processing of CS project files failed, reason: " + ex.Message);
         }
     }
 }
示例#4
0
        private string ProjectText(MonoIsland island, SolutionSynchronizer.Mode mode, Dictionary <string, string> allAssetsProjectParts, string[] additionalDefines, List <MonoIsland> allProjectIslands)
        {
            StringBuilder stringBuilder           = new StringBuilder(this.ProjectHeader(island, additionalDefines));
            List <string> list                    = new List <string>();
            List <Match>  list2                   = new List <Match>();
            bool          isBuildingEditorProject = island._output.EndsWith("-Editor.dll");

            string[] files = island._files;
            for (int j = 0; j < files.Length; j++)
            {
                string text = files[j];
                if (this.ShouldFileBePartOfSolution(text))
                {
                    string b     = Path.GetExtension(text).ToLower();
                    string text2 = (!Path.IsPathRooted(text)) ? Path.Combine(this._projectDirectory, text) : text;
                    if (".dll" != b)
                    {
                        string arg = "Compile";
                        stringBuilder.AppendFormat("     <{0} Include=\"{1}\" />{2}", arg, this.EscapedRelativePathFor(text2), SolutionSynchronizer.WindowsNewline);
                    }
                    else
                    {
                        list.Add(text2);
                    }
                }
            }
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(island._output);
            string value;

            if (allAssetsProjectParts.TryGetValue(fileNameWithoutExtension, out value))
            {
                stringBuilder.Append(value);
            }
            List <string> list3 = new List <string>();

            foreach (string current in list.Union(island._references))
            {
                if (!current.EndsWith("/UnityEditor.dll") && !current.EndsWith("/UnityEngine.dll") && !current.EndsWith("\\UnityEditor.dll") && !current.EndsWith("\\UnityEngine.dll"))
                {
                    Match match = SolutionSynchronizer.scriptReferenceExpression.Match(current);
                    if (match.Success)
                    {
                        SupportedLanguage languageFromExtension = ScriptCompilers.GetLanguageFromExtension(island.GetExtensionOfSourceFiles());
                        ScriptingLanguage scriptingLanguage     = (ScriptingLanguage)Enum.Parse(typeof(ScriptingLanguage), languageFromExtension.GetLanguageName(), true);
                        if (mode == SolutionSynchronizer.Mode.UnityScriptAsUnityProj || scriptingLanguage == ScriptingLanguage.CSharp)
                        {
                            string dllName = match.Groups["dllname"].Value;
                            if (allProjectIslands.Any((MonoIsland i) => Path.GetFileName(i._output) == dllName))
                            {
                                list2.Add(match);
                                continue;
                            }
                        }
                    }
                    string text3 = (!Path.IsPathRooted(current)) ? Path.Combine(this._projectDirectory, current) : current;
                    if (AssemblyHelper.IsManagedAssembly(text3))
                    {
                        if (AssemblyHelper.IsInternalAssembly(text3))
                        {
                            if (!SolutionSynchronizer.IsAdditionalInternalAssemblyReference(isBuildingEditorProject, text3))
                            {
                                continue;
                            }
                            string fileName = Path.GetFileName(text3);
                            if (list3.Contains(fileName))
                            {
                                continue;
                            }
                            list3.Add(fileName);
                        }
                        text3 = text3.Replace("\\", "/");
                        text3 = text3.Replace("\\\\", "/");
                        stringBuilder.AppendFormat(" <Reference Include=\"{0}\">{1}", Path.GetFileNameWithoutExtension(text3), SolutionSynchronizer.WindowsNewline);
                        stringBuilder.AppendFormat(" <HintPath>{0}</HintPath>{1}", text3, SolutionSynchronizer.WindowsNewline);
                        stringBuilder.AppendFormat(" </Reference>{0}", SolutionSynchronizer.WindowsNewline);
                    }
                }
            }
            if (0 < list2.Count)
            {
                stringBuilder.AppendLine("  </ItemGroup>");
                stringBuilder.AppendLine("  <ItemGroup>");
                foreach (Match current2 in list2)
                {
                    EditorBuildRules.TargetAssembly targetAssemblyDetails = EditorCompilationInterface.Instance.GetTargetAssemblyDetails(current2.Groups["dllname"].Value);
                    ScriptingLanguage language = ScriptingLanguage.None;
                    if (targetAssemblyDetails != null)
                    {
                        language = (ScriptingLanguage)Enum.Parse(typeof(ScriptingLanguage), targetAssemblyDetails.Language.GetLanguageName(), true);
                    }
                    string value2 = current2.Groups["project"].Value;
                    stringBuilder.AppendFormat("    <ProjectReference Include=\"{0}{1}\">{2}", value2, SolutionSynchronizer.GetProjectExtension(language), SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendFormat("      <Project>{{{0}}}</Project>", this.ProjectGuid(Path.Combine("Temp", current2.Groups["project"].Value + ".dll")), SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendFormat("      <Name>{0}</Name>", value2, SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendLine("    </ProjectReference>");
                }
            }
            stringBuilder.Append(this.ProjectFooter(island));
            return(stringBuilder.ToString());
        }
        private string ProjectText(MonoIsland island, SolutionSynchronizer.Mode mode, string allAssetsProject)
        {
            StringBuilder stringBuilder           = new StringBuilder(this.ProjectHeader(island));
            List <string> first                   = new List <string>();
            List <Match>  matchList               = new List <Match>();
            bool          isBuildingEditorProject = island._output.EndsWith("-Editor.dll");

            foreach (string file1 in island._files)
            {
                string lower = Path.GetExtension(file1).ToLower();
                string file2 = !Path.IsPathRooted(file1) ? Path.Combine(this._projectDirectory, file1) : file1;
                if (".dll" != lower)
                {
                    string str = "Compile";
                    stringBuilder.AppendFormat("     <{0} Include=\"{1}\" />{2}", (object)str, (object)this.EscapedRelativePathFor(file2), (object)SolutionSynchronizer.WindowsNewline);
                }
                else
                {
                    first.Add(file2);
                }
            }
            stringBuilder.Append(allAssetsProject);
            foreach (string str1 in first.Union <string>((IEnumerable <string>)island._references))
            {
                if (!str1.EndsWith("/UnityEditor.dll") && !str1.EndsWith("/UnityEngine.dll") && (!str1.EndsWith("\\UnityEditor.dll") && !str1.EndsWith("\\UnityEngine.dll")))
                {
                    Match match = SolutionSynchronizer.scriptReferenceExpression.Match(str1);
                    if (match.Success && (mode == SolutionSynchronizer.Mode.UnityScriptAsUnityProj || (int)Enum.Parse(typeof(ScriptingLanguage), match.Groups["language"].Value, true) == 2))
                    {
                        matchList.Add(match);
                    }
                    else
                    {
                        string str2 = !Path.IsPathRooted(str1) ? Path.Combine(this._projectDirectory, str1) : str1;
                        if (AssemblyHelper.IsManagedAssembly(str2) && (!AssemblyHelper.IsInternalAssembly(str2) || SolutionSynchronizer.IsInternalAssemblyThatShouldBeReferenced(isBuildingEditorProject, str2)))
                        {
                            string path = str2.Replace("\\", "/").Replace("\\\\", "/");
                            stringBuilder.AppendFormat(" <Reference Include=\"{0}\">{1}", (object)Path.GetFileNameWithoutExtension(path), (object)SolutionSynchronizer.WindowsNewline);
                            stringBuilder.AppendFormat(" <HintPath>{0}</HintPath>{1}", (object)path, (object)SolutionSynchronizer.WindowsNewline);
                            stringBuilder.AppendFormat(" </Reference>{0}", (object)SolutionSynchronizer.WindowsNewline);
                        }
                    }
                }
            }
            if (0 < matchList.Count)
            {
                stringBuilder.AppendLine("  </ItemGroup>");
                stringBuilder.AppendLine("  <ItemGroup>");
                using (List <Match> .Enumerator enumerator = matchList.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Match  current = enumerator.Current;
                        string str     = current.Groups["project"].Value;
                        stringBuilder.AppendFormat("    <ProjectReference Include=\"{0}{1}\">{2}", (object)str, (object)SolutionSynchronizer.GetProjectExtension((ScriptingLanguage)Enum.Parse(typeof(ScriptingLanguage), current.Groups["language"].Value, true)), (object)SolutionSynchronizer.WindowsNewline);
                        stringBuilder.AppendFormat("      <Project>{{{0}}}</Project>", (object)this.ProjectGuid(Path.Combine("Temp", current.Groups["project"].Value + ".dll")), (object)SolutionSynchronizer.WindowsNewline);
                        stringBuilder.AppendFormat("      <Name>{0}</Name>", (object)str, (object)SolutionSynchronizer.WindowsNewline);
                        stringBuilder.AppendLine("    </ProjectReference>");
                    }
                }
            }
            stringBuilder.Append(this.ProjectFooter(island));
            return(stringBuilder.ToString());
        }