コード例 #1
0
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 2))
            {
                pr.Step("Generating C# project...".TTR());

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = GodotSharpDirs.ProjectAssemblyName;

                string guid = CsProjOperations.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "ExportDebug", "ExportRelease"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog("Failed to save solution. Exception message: ".TTR() + e.Message);
                        return(false);
                    }

                    pr.Step("Done".TTR());

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project.".TTR());
                }

                return(true);
            }
        }
コード例 #2
0
        private static bool BuildProjectBlocking(BuildInfo buildInfo)
        {
            if (!File.Exists(buildInfo.Solution))
            {
                return(true); // No solution to build
            }
            // Make sure the API assemblies are up to date before building the project.
            // We may not have had the chance to update the release API assemblies, and the debug ones
            // may have been deleted by the user at some point after they were loaded by the Godot editor.
            string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(buildInfo.Configuration == "ExportRelease" ? "Release" : "Debug");

            if (!string.IsNullOrEmpty(apiAssembliesUpdateError))
            {
                ShowBuildErrorDialog("Failed to update the Godot API assemblies");
                return(false);
            }

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
        public static bool BuildProjectBlocking(string config, IEnumerable <string> godotDefines)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            // Make sure the API assemblies are up to date before building the project.
            // We may not have had the chance to update the release API assemblies, and the debug ones
            // may have been deleted by the user at some point after they were loaded by the Godot editor.
            string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(config == "ExportRelease" ? "Release" : "Debug");

            if (!string.IsNullOrEmpty(apiAssembliesUpdateError))
            {
                ShowBuildErrorDialog("Failed to update the Godot API assemblies");
                return(false);
            }

            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
            var buildTool      = (BuildTool)editorSettings.GetSetting("mono/builds/build_tool");

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, targets: new[] { "Restore", "Build" }, config);

                bool escapeNeedsDoubleBackslash = buildTool == BuildTool.MsBuildMono || buildTool == BuildTool.DotnetCli;

                // Add Godot defines
                string constants = !escapeNeedsDoubleBackslash ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";

                foreach (var godotDefine in godotDefines)
                {
                    constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
                }

                if (Internal.GodotIsRealTDouble())
                {
                    constants += "GODOT_REAL_T_IS_DOUBLE;";
                }

                constants += !escapeNeedsDoubleBackslash ? "\"" : "\\\"";

                buildInfo.CustomProperties.Add(constants);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #4
0
        private static bool PublishProjectBlocking(BuildInfo buildInfo)
        {
            using var pr = new EditorProgress("dotnet_publish_project", "Publishing .NET project...", 1);

            pr.Step("Running dotnet publish", 0);

            if (!Publish(buildInfo))
            {
                ShowBuildErrorDialog("Failed to publish .NET project");
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public static bool BuildProjectBlocking(string config, IEnumerable <string> godotDefines)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            string apiConfig = config == "Release" ? "Release" : "Debug";

            if (!MakeApiAssembly(ApiAssemblyType.Core, apiConfig))
            {
                return(false);
            }

            if (!MakeApiAssembly(ApiAssemblyType.Editor, apiConfig))
            {
                return(false);
            }

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new MonoBuildInfo(GodotSharpDirs.ProjectSlnPath, config);

                // Add Godot defines
                string constants = OS.IsWindows() ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";

                foreach (var godotDefine in godotDefines)
                {
                    constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
                }

                if (Internal.GodotIsRealTDouble())
                {
                    constants += "GODOT_REAL_T_IS_DOUBLE;";
                }

                constants += OS.IsWindows() ? "\"" : "\\\"";

                buildInfo.CustomProperties.Add(constants);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        public static bool BuildProjectBlocking(string config, IEnumerable <string> godotDefines)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            // Make sure to update the API assemblies if they happen to be missing. Just in
            // case the user decided to delete them at some point after they were loaded.
            Internal.UpdateApiAssembliesFromPrebuilt();

            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
            var buildTool      = (BuildTool)editorSettings.GetSetting("mono/builds/build_tool");

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, config);

                // Add Godot defines
                string constants = buildTool == BuildTool.MsBuildVs ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";

                foreach (var godotDefine in godotDefines)
                {
                    constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
                }

                if (Internal.GodotIsRealTDouble())
                {
                    constants += "GODOT_REAL_T_IS_DOUBLE;";
                }

                constants += buildTool == BuildTool.MsBuildVs ? "\"" : "\\\"";

                buildInfo.CustomProperties.Add(constants);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #7
0
        private static bool CleanProjectBlocking(BuildInfo buildInfo)
        {
            if (!File.Exists(buildInfo.Solution))
            {
                return(true); // No solution to clean
            }
            using var pr = new EditorProgress("dotnet_clean_project", "Cleaning .NET project...", 1);

            pr.Step("Cleaning project solution", 0);

            if (!Build(buildInfo))
            {
                ShowBuildErrorDialog("Failed to clean project solution");
                return(false);
            }

            return(true);
        }
コード例 #8
0
ファイル: BuildManager.cs プロジェクト: Edelweiss303/godot-1
        public static bool BuildProjectBlocking(string config, [CanBeNull] string platform = null)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            // Make sure the API assemblies are up to date before building the project.
            // We may not have had the chance to update the release API assemblies, and the debug ones
            // may have been deleted by the user at some point after they were loaded by the Godot editor.
            string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(config == "ExportRelease" ? "Release" : "Debug");

            if (!string.IsNullOrEmpty(apiAssembliesUpdateError))
            {
                ShowBuildErrorDialog("Failed to update the Godot API assemblies");
                return(false);
            }

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, targets: new[] { "Build" }, config, restore: true);

                // If a platform was not specified, try determining the current one. If that fails, let MSBuild auto-detect it.
                if (platform != null || OS.PlatformNameMap.TryGetValue(Godot.OS.GetName(), out platform))
                {
                    buildInfo.CustomProperties.Add($"GodotTargetPlatform={platform}");
                }

                if (Internal.GodotIsRealTDouble())
                {
                    buildInfo.CustomProperties.Add("GodotRealTIsDouble=true");
                }

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #9
0
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 3))
            {
                pr.Step("Generating C# project...".TTR());

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = (string)ProjectSettings.GetSetting("application/config/name");
                if (name.Empty())
                {
                    name = "UnnamedProject";
                }

                string guid = CsProjOperations.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "Release", "Tools"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog("Failed to save solution. Exception message: ".TTR() + e.Message);
                        return(false);
                    }

                    pr.Step("Updating Godot API assemblies...".TTR());

                    string debugApiAssembliesError = Internal.UpdateApiAssembliesFromPrebuilt("Debug");

                    if (!string.IsNullOrEmpty(debugApiAssembliesError))
                    {
                        ShowErrorDialog("Failed to update the Godot API assemblies: " + debugApiAssembliesError);
                        return(false);
                    }

                    string releaseApiAssembliesError = Internal.UpdateApiAssembliesFromPrebuilt("Release");

                    if (!string.IsNullOrEmpty(releaseApiAssembliesError))
                    {
                        ShowErrorDialog("Failed to update the Godot API assemblies: " + releaseApiAssembliesError);
                        return(false);
                    }

                    pr.Step("Done".TTR());

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project.".TTR());
                }

                return(true);
            }
        }
コード例 #10
0
ファイル: GodotSharpEditor.cs プロジェクト: vkkevin/godot
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 2))
            {
                pr.Step("Generating C# project...".TTR());

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = (string)ProjectSettings.GetSetting("application/config/name");
                if (name.Empty())
                {
                    name = "UnnamedProject";
                }

                string guid = CSharpProject.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "Release", "Tools"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog("Failed to save solution. Exception message: ".TTR() + e.Message);
                        return(false);
                    }

                    // Make sure to update the API assemblies if they happen to be missing. Just in
                    // case the user decided to delete them at some point after they were loaded.
                    Internal.UpdateApiAssembliesFromPrebuilt();

                    pr.Step("Done".TTR());

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project.".TTR());
                }

                return(true);
            }
        }
コード例 #11
0
ファイル: GodotSharpEditor.cs プロジェクト: rohithbt/godot
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...", 2)) // TTR("Generating solution...")
            {
                pr.Step("Generating C# project...");                                                   // TTR("Generating C# project...")

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = (string)ProjectSettings.GetSetting("application/config/name");
                if (name.Empty())
                {
                    name = "UnnamedProject";
                }

                string guid = CSharpProject.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "Release", "Tools"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog($"Failed to save solution. Exception message: {e.Message}"); // TTR
                        return(false);
                    }

                    string apiConfig = "Debug";

                    if (!GodotSharpBuilds.MakeApiAssembly(ApiAssemblyType.Core, apiConfig))
                    {
                        return(false);
                    }

                    if (!GodotSharpBuilds.MakeApiAssembly(ApiAssemblyType.Editor, apiConfig))
                    {
                        return(false);
                    }

                    pr.Step("Done"); // TTR("Done")

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project."); // TTR
                }

                return(true);
            }
        }
コード例 #12
0
        public static bool MakeApiAssembly(ApiAssemblyType apiType, string config)
        {
            string apiName = apiType == ApiAssemblyType.Core ? ApiAssemblyNames.Core : ApiAssemblyNames.Editor;

            string editorPrebuiltApiDir = Path.Combine(GodotSharpDirs.DataEditorPrebuiltApiDir, config);
            string resAssembliesDir     = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, config);

            if (File.Exists(Path.Combine(editorPrebuiltApiDir, $"{apiName}.dll")))
            {
                using (var copyProgress = new EditorProgress("mono_copy_prebuilt_api_assembly", $"Copying prebuilt {apiName} assembly...", 1))
                {
                    copyProgress.Step($"Copying {apiName} assembly", 0);
                    return(CopyApiAssembly(editorPrebuiltApiDir, resAssembliesDir, apiName, apiType));
                }
            }

            const string apiSolutionName = ApiAssemblyNames.SolutionName;

            using (var pr = new EditorProgress($"mono_build_release_{apiSolutionName}", $"Building {apiSolutionName} solution...", 3))
            {
                pr.Step($"Generating {apiSolutionName} solution", 0);

                string apiSlnDir  = Path.Combine(GodotSharpDirs.MonoSolutionsDir, _ApiFolderName(ApiAssemblyType.Core));
                string apiSlnFile = Path.Combine(apiSlnDir, $"{apiSolutionName}.sln");

                if (!Directory.Exists(apiSlnDir) || !File.Exists(apiSlnFile))
                {
                    var bindingsGenerator = new BindingsGenerator();

                    if (!Godot.OS.IsStdoutVerbose())
                    {
                        bindingsGenerator.LogPrintEnabled = false;
                    }

                    Error err = bindingsGenerator.GenerateCsApi(apiSlnDir);
                    if (err != Error.Ok)
                    {
                        ShowBuildErrorDialog($"Failed to generate {apiSolutionName} solution. Error: {err}");
                        return(false);
                    }
                }

                pr.Step($"Building {apiSolutionName} solution", 1);

                if (!BuildApiSolution(apiSlnDir, config))
                {
                    return(false);
                }

                pr.Step($"Copying {apiName} assembly", 2);

                // Copy the built assembly to the assemblies directory
                string apiAssemblyDir = Path.Combine(apiSlnDir, apiName, "bin", config);
                if (!CopyApiAssembly(apiAssemblyDir, resAssembliesDir, apiName, apiType))
                {
                    return(false);
                }
            }

            return(true);
        }