private void AddVersionUpdatePostSteps(TargetInfo Target)
    {
        ReadOnlyBuildVersion BuildVersion = Target.Version;
        string VersionString              = string.Format("{0}.{1}.{2}.{3}", BuildVersion.MajorVersion, BuildVersion.MinorVersion, BuildVersion.PatchVersion, BuildVersion.Changelist);
        string CustomAssemblyInfoPath     = Path.Combine(GetPropertiesPath(), "GeneratedAssemblyInfo.cs");
        string CustomAssemblyTemplatePath = Path.Combine(GetPropertiesPath(), "GeneratedAssemblyInfo.cs.Template");
        string Disclaimer = "// Warning. This is an AUTO-GENERATED file used for automatic version management. Please add your changes to GeneratedAssemblyInfo.cs.template.";

        PostBuildSteps.Add(string.Format(@"echo Generating custom AssemblyInfo.cs with assembly version: {0}", VersionString));
        PostBuildSteps.Add(string.Format(@"echo ""copy /Y {0} {1}""", CustomAssemblyTemplatePath, CustomAssemblyInfoPath));
        PostBuildSteps.Add(string.Format(@"copy /Y ""{0}"" ""{1}""", CustomAssemblyTemplatePath, CustomAssemblyInfoPath));
        // Add a disclaimer on the auto-generated file.
        PostBuildSteps.Add(string.Format(@"powershell -Command ""(Get-Content -Path ""{0}"") -replace '<AutoGenerationDisclaimer>', '{1}' | Out-File -encoding UTF8 {0}""; exit", CustomAssemblyInfoPath, Disclaimer));
        // Update the assembly version of the plugin.
        PostBuildSteps.Add(string.Format(@"powershell -Command ""(Get-Content -Path ""{0}"") -replace '<AssemblyVersion>', '{1}' | Out-File -encoding UTF8 {0}""; exit", CustomAssemblyInfoPath, VersionString));
        PostBuildSteps.Add(string.Format(@"powershell -Command ""(Get-Content -Path ""{0}"") -replace '<AssemblyFileVersion>', '{1}' | Out-File -encoding UTF8 {0}""; exit", CustomAssemblyInfoPath, VersionString));
    }
Пример #2
0
        /// <summary>
        /// Optionally compiles and loads target rules assembly.
        /// </summary>
        /// <param name="Properties"></param>
        /// <param name="TargetsDllFilename"></param>
        /// <param name="DoNotCompile"></param>
        /// <param name="TargetScripts"></param>
        private static void CompileAndLoadTargetsAssembly(ProjectProperties Properties, FileReference TargetsDllFilename, bool DoNotCompile, List <FileReference> TargetScripts)
        {
            CommandUtils.LogVerbose("Compiling targets DLL: {0}", TargetsDllFilename);

            var ReferencedAssemblies = new List <string>()
            {
                "System.dll",
                "System.Core.dll",
                "System.Xml.dll",
                typeof(UnrealBuildTool.PlatformExports).Assembly.Location
            };
            List <string> PreprocessorDefinitions = RulesAssembly.GetPreprocessorDefinitions();
            var           TargetsDLL       = DynamicCompilation.CompileAndLoadAssembly(TargetsDllFilename, TargetScripts, ReferencedAssemblies, PreprocessorDefinitions, DoNotCompile);
            var           AllCompiledTypes = TargetsDLL.GetTypes();

            foreach (Type TargetType in AllCompiledTypes)
            {
                // Find TargetRules but skip all "UE4Editor", "UE4Game" targets.
                if (typeof(TargetRules).IsAssignableFrom(TargetType))
                {
                    string TargetName = GetTargetName(TargetType);

                    ReadOnlyBuildVersion Version         = new ReadOnlyBuildVersion(BuildVersion.ReadDefault());
                    TargetInfo           DummyTargetInfo = new TargetInfo(TargetName, BuildHostPlatform.Current.Platform, UnrealTargetConfiguration.Development, "", Properties.RawProjectPath, Version);

                    // Create an instance of this type
                    CommandUtils.LogVerbose("Creating target rules object: {0}", TargetType.Name);
                    TargetRules Rules = Activator.CreateInstance(TargetType, DummyTargetInfo) as TargetRules;
                    CommandUtils.LogVerbose("Adding target: {0} ({1})", TargetType.Name, Rules.Type);

                    SingleTargetProperties TargetData;
                    TargetData.TargetName = GetTargetName(TargetType);
                    TargetData.Rules      = Rules;
                    if (Rules.Type == global::UnrealBuildTool.TargetType.Program)
                    {
                        Properties.Programs.Add(TargetData);
                    }
                    else
                    {
                        Properties.Targets.Add(Rules.Type, TargetData);
                    }
                }
            }
        }