コード例 #1
0
    private void InjectVersionInfo()
    {
        var targetPortableExecutable = new PortableExecutable(TargetFilePath);
        var targetVersionInfo        = targetPortableExecutable.TryGetVersionInfo();

        var appHostPortableExecutable = new PortableExecutable(AppHostFilePath);

        appHostPortableExecutable.RemoveVersionInfo();

        if (targetVersionInfo is not null)
        {
            var bootstrapperVersion = typeof(BootstrapperTask).Assembly.GetName().Version.ToString(3);

            appHostPortableExecutable.SetVersionInfo(new VersionInfoBuilder()
                                                     .SetAll(targetVersionInfo)
                                                     .SetFileFlags(FileFlags.None)
                                                     .SetFileType(FileType.Application)
                                                     .SetFileSubType(FileSubType.Unknown)
                                                     .SetAttribute(VersionAttributeName.InternalName, AppHostFileName)
                                                     .SetAttribute(VersionAttributeName.OriginalFilename, AppHostFileName)
                                                     .SetAttribute("AppHost", $".NET Runtime Bootstrapper v{bootstrapperVersion} ({Variant})")
                                                     .Build()
                                                     );

            Log.LogMessage("Injected version info into '{0}'.", AppHostFileName);
        }
        else
        {
            // This is very unusual, so log a warning instead of info
            Log.LogWarning("Could not read version info from '{0}'.", TargetFileName);
        }
    }