总结:我会花一些时间来建立构建和部署方案。这是一个前期工作,但是一个通用的解决方案可以在设置后根据需要进行扩展。
您可以使用 Ant 脚本完成第 1 步。您首先要安装 Ant,然后编写一个简短的 build.xml 以包含类似 this example 的内容。正确安装 Ant 后,您只需切换到 build.xml 所在的目录并运行“ant”即可。
对于第 2 步到第 6 步,由于您需要清理目标、管理服务等,我会考虑生成 MSI 安装程序或可执行文件。我首选的 MSI 工具是Advanced Installer。您将在the list of features 下看到免费软件版本允许您在安装和卸载时控制(启动、停止、安装、卸载)Windows 服务。
(旁注:我们已经使用 Advanced Installer Enterprise 四年了。它在不断改进,是一款非常优质的产品。您不会失望的。)
您也可以通过 Ant 控制 MSI 创建。这是我的 build.xml 中的一个片段,它调用了几个宏来编译和部署我维护的一个产品:
<target name="myproduct-installer" depends="unzip-myproductdocs">
<build-ai-installer product.name="MyProduct" installer.path="setup/installs/MyProduct" project.file="MyProduct.aip" />
</target>
<target name="release-myproduct-installer">
<release-AI-installer product.name="MyProduct" installer.path="setup/installs/MyProduct" product.path="${some-predefined-target}" />
</target>
以下是上面使用的宏:
<macrodef name="build-ai-installer">
<attribute name="product.name" />
<attribute name="installer.path" />
<attribute name="project.file" />
<sequential>
<echo message="Making installer at @{installer.path}" />
<mkdir dir="@{installer.path}/newInstall" />
<exec dir="@{installer.path}" executable="${env.ADVANCEDINSTALLER}" failonerror="true">
<arg line="/edit @{project.file} /SetVersion ${product.version}" />
</exec>
<exec dir="@{installer.path}" executable="${env.ADVANCEDINSTALLER}" failonerror="true">
<arg line="/build @{project.file}" />
</exec>
</sequential>
</macrodef>
<macrodef name="release-AI-installer">
<attribute name="product.name" />
<attribute name="installer.path" />
<attribute name="product.path" />
<sequential>
<copy todir="@{product.path}">
<fileset dir="@{installer.path}/newInstall" />
</copy>
</sequential>
</macrodef>
这些宏使用名为 env.ADVANCEDINSTALLER 的 Windows 环境变量。更简单的构建设置只需设置 Ant 属性并删除“env”。前缀:
<property name="ADVANCEDINSTALLER" value="path-to-AdvancedInstaller.com" />
这种级别的自动化一旦启动并运行,就会带来回报。但如果超出您的需要(我不会感到惊讶),this answer 可能会有所帮助。