我有一个包含 2 个 Web 应用程序项目的解决方案,我已经配置了对 IIS 测试环境的持续集成和部署。它工作得很好,我对此非常满意。
现在,我想在部署的网站主页中显示一些信息,让我知道当前的构建是什么。有没有办法检索这种信息?
提前致谢
Yes, couple of ways to do this
Usually as part of your CI build steps, you would add versioning numbers, company details, sign libraries etc. You will be able to read this info when a request comes from the library with updated metadata. Code snippet to try, make sure to find correct dll though, as on IIS it may not be the executing assembly.
Similarly as part of the build process you may do xml-poke
or xml-transform
to insert some values into the web.config, for example into the <appsettings>
section. MS build sample. You would likely to use ConfigurationManager.AppSettings
from the web application.
构建时可以生成一个非常棒的 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>