Esempio n. 1
0
        public static ProjectRootElement GenGameProject(string name)
        {
            if (name.Length == 0)
            {
                throw new ArgumentException("Project name is empty", nameof(name));
            }

            var root = ProjectRootElement.Create(NewProjectFileOptions.None);

            root.Sdk = $"{GodotSdkNameToUse}/{GodotSdkVersionToUse}";

            var mainGroup = root.AddPropertyGroup();

            mainGroup.AddProperty("TargetFramework", "net472");

            string sanitizedName = IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true);

            // If the name is not a valid namespace, manually set RootNamespace to a sanitized one.
            if (sanitizedName != name)
            {
                mainGroup.AddProperty("RootNamespace", sanitizedName);
            }

            return(root);
        }
Esempio n. 2
0
        public static ProjectRootElement CreateLibraryProject(string name, string defaultConfig, out ProjectPropertyGroupElement mainGroup)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException($"{nameof(name)} cannot be empty", nameof(name));
            }

            var root = ProjectRootElement.Create();

            root.DefaultTargets = "Build";

            mainGroup = root.AddPropertyGroup();
            mainGroup.AddProperty("Configuration", defaultConfig).Condition = " '$(Configuration)' == '' ";
            mainGroup.AddProperty("Platform", "AnyCPU").Condition           = " '$(Platform)' == '' ";
            mainGroup.AddProperty("ProjectGuid", "{" + Guid.NewGuid().ToString().ToUpper() + "}");
            mainGroup.AddProperty("OutputType", "Library");
            mainGroup.AddProperty("OutputPath", Path.Combine("bin", "$(Configuration)"));
            mainGroup.AddProperty("RootNamespace", IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true));
            mainGroup.AddProperty("AssemblyName", name);
            mainGroup.AddProperty("TargetFrameworkVersion", "v4.7");
            mainGroup.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());

            var exportDebugGroup = root.AddPropertyGroup();

            exportDebugGroup.Condition = " '$(Configuration)|$(Platform)' == 'ExportDebug|AnyCPU' ";
            exportDebugGroup.AddProperty("DebugSymbols", "true");
            exportDebugGroup.AddProperty("DebugType", "portable");
            exportDebugGroup.AddProperty("Optimize", "false");
            exportDebugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;");
            exportDebugGroup.AddProperty("ErrorReport", "prompt");
            exportDebugGroup.AddProperty("WarningLevel", "4");
            exportDebugGroup.AddProperty("ConsolePause", "false");

            var exportReleaseGroup = root.AddPropertyGroup();

            exportReleaseGroup.Condition = " '$(Configuration)|$(Platform)' == 'ExportRelease|AnyCPU' ";
            exportReleaseGroup.AddProperty("DebugType", "portable");
            exportReleaseGroup.AddProperty("Optimize", "true");
            exportReleaseGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;");
            exportReleaseGroup.AddProperty("ErrorReport", "prompt");
            exportReleaseGroup.AddProperty("WarningLevel", "4");
            exportReleaseGroup.AddProperty("ConsolePause", "false");

            // References
            var referenceGroup = root.AddItemGroup();

            referenceGroup.AddItem("Reference", "System");
            var frameworkRefAssembliesItem = referenceGroup.AddItem("PackageReference", "Microsoft.NETFramework.ReferenceAssemblies");

            // Use metadata (child nodes) instead of attributes for the PackageReference.
            // This is for compatibility with 3.2, where GodotTools uses an old Microsoft.Build.
            frameworkRefAssembliesItem.AddMetadata("Version", "1.0.0");
            frameworkRefAssembliesItem.AddMetadata("PrivateAssets", "All");

            root.AddImport(Path.Combine("$(MSBuildBinPath)", "Microsoft.CSharp.targets").Replace("/", "\\"));

            return(root);
        }
Esempio n. 3
0
        public static ProjectRootElement CreateLibraryProject(string name, string defaultConfig, out ProjectPropertyGroupElement mainGroup)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException($"{nameof(name)} cannot be empty", nameof(name));
            }

            var root = ProjectRootElement.Create();

            root.DefaultTargets = "Build";

            mainGroup = root.AddPropertyGroup();
            mainGroup.AddProperty("Configuration", defaultConfig).Condition = " '$(Configuration)' == '' ";
            mainGroup.AddProperty("Platform", "AnyCPU").Condition           = " '$(Platform)' == '' ";
            mainGroup.AddProperty("ProjectGuid", "{" + Guid.NewGuid().ToString().ToUpper() + "}");
            mainGroup.AddProperty("OutputType", "Library");
            mainGroup.AddProperty("OutputPath", Path.Combine("bin", "$(Configuration)"));
            mainGroup.AddProperty("RootNamespace", IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true));
            mainGroup.AddProperty("AssemblyName", name);
            mainGroup.AddProperty("TargetFrameworkVersion", "v4.5");
            mainGroup.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());

            var debugGroup = root.AddPropertyGroup();

            debugGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ";
            debugGroup.AddProperty("DebugSymbols", "true");
            debugGroup.AddProperty("DebugType", "portable");
            debugGroup.AddProperty("Optimize", "false");
            debugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;");
            debugGroup.AddProperty("ErrorReport", "prompt");
            debugGroup.AddProperty("WarningLevel", "4");
            debugGroup.AddProperty("ConsolePause", "false");

            var releaseGroup = root.AddPropertyGroup();

            releaseGroup.Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ";
            releaseGroup.AddProperty("DebugType", "portable");
            releaseGroup.AddProperty("Optimize", "true");
            releaseGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;");
            releaseGroup.AddProperty("ErrorReport", "prompt");
            releaseGroup.AddProperty("WarningLevel", "4");
            releaseGroup.AddProperty("ConsolePause", "false");

            // References
            var referenceGroup = root.AddItemGroup();

            referenceGroup.AddItem("Reference", "System");

            root.AddImport(Path.Combine("$(MSBuildBinPath)", "Microsoft.CSharp.targets").Replace("/", "\\"));

            return(root);
        }