【问题标题】:What is the best way to get Build Info in a Web application?在 Web 应用程序中获取构建信息的最佳方式是什么?
【发布时间】:2013-08-25 11:45:36
【问题描述】:

我有一个包含 2 个 Web 应用程序项目的解决方案,我已经配置了对 IIS 测试环境的持续集成和部署。 它运行良好,我对此非常满意。

现在,我想在部署的网站主页中显示一些信息,让我知道当前的构建是什么。 有什么办法可以检索到这类信息?

提前致谢

【问题讨论】:

    标签: c# msbuild


    【解决方案1】:

    是的,有几种方法可以做到这一点

    读取程序集信息

    通常作为 CI 构建步骤的一部分,您会添加版本号、公司详细信息、签名库等。当请求来自包含更新元数据的库时,您将能够读取此信息。 Code snippet to try,请确保找到正确的 dll,因为在 IIS 上它可能不是正在执行的程序集。

    嵌入自定义应用配置值

    类似地,作为构建过程的一部分,您可以使用xml-pokexml-transform 将一些值插入到 web.config 中,例如插入到<appsettings> 部分。 MS build sample。您可能会在 Web 应用程序中使用 ConfigurationManager.AppSettings

    【讨论】:

    • 谢谢你,我选择了第一个选项。效果很好
    【解决方案2】:

    构建时可以生成一个非常棒的 XML 文件。称为 BuildInfo.config 文件。 https://msdn.microsoft.com/en-us/library/dn449058(v=vs.120).aspx

    /p:GenerateBuildInfoConfigFile=True

    在 Web 项目的根目录下创建 BuildInfo.config

    <?xml version="1.0" encoding="utf-8"?>
    <DeploymentEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/VisualStudio/DeploymentEvent/2013/06">
      <ProjectName>Agriculture</ProjectName>
      <SourceControl type="TFS">
        <TfsSourceControl>
          <ProjectItemSpec>$/ServerPath/To/Your/Project.sln</ProjectItemSpec>
          <ProjectVersionSpec>C39469</ProjectVersionSpec>
        </TfsSourceControl>
      </SourceControl>
      <Build type="TeamBuild">
        <MSBuild>
          <BuildDefinition kind="informative, summary">CIA_TEST</BuildDefinition>
          <BuildLabel kind="label">YOUR_PROJECT_20170406.04</BuildLabel>
          <BuildId kind="id">a7e16be8-141d-4193-b200-b57b19f1564a,vstfs:///Build/Build/34814</BuildId>
          <BuildTimestamp kind="informative, summary">Thu, 06 Apr 2017 16:49:22 GMT</BuildTimestamp>
          <Configuration kind="informative">Release</Configuration>
          <Platform kind="informative">AnyCPU</Platform>
        </MSBuild>
      </Build>
    </DeploymentEvent>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多