我只能通过执行一次 msbuild/publish 来获得成功,然后编写一个单独的“部署”程序来更改和重新签署清单,因为它们移动到每个环境。它将部署到 QA 并为其提供新名称和配置文件。然后稍后再次“部署”到生产环境,同时给它一个新的名称和配置文件。
该过程需要重命名以删除 .deploy 扩展名,替换配置文件,更改应用程序清单,更改部署清单,(在我的情况下,更新 .xlsx 文件,因为我正在执行 vsto excel 加载项),然后重新签名应用程序清单,恢复 .deploy 扩展名,重新签名部署清单,最后将结果复制到部署位置。
这导致部署到 QA 时,“单击一次”会在添加/删除程序中创建“Application-QA”,而生产部署会在“单击一次”时创建“Application-PROD”。两者可以同时运行,因为程序集名称和“solutionId”guid 已更新为在每个环境中都不同。
下面是一些关于如何更改应用程序和部署清单以在每个环境中为它们赋予唯一名称的代码。如果您决定采用这种方法并且想要辞职代码,我可以提供帮助。
Private Function UpdateAppManifestBasedOnTarget(caller As IReleaseExecutionCaller, appName As String, appManifestFileInfo As IO.FileInfo) As String
Log.Write(Me.Name, String.Format("update the app manifest based on the target environment..."))
Dim appManifestXML As New Xml.XmlDocument()
Dim appManifestNamespaces As New Xml.XmlNamespaceManager(appManifestXML.NameTable)
appManifestNamespaces.AddNamespace("asmv1", "urn:schemas-microsoft-com:asm.v1")
appManifestNamespaces.AddNamespace("vstav3", "urn:schemas-microsoft-com:vsta.v3")
appManifestNamespaces.AddNamespace("vstov4", "urn:schemas-microsoft-com:vsto.v4")
appManifestXML.Load(appManifestFileInfo.FullName)
'assemblyIdentity
Dim assemblyNode = appManifestXML.SelectSingleNode("/asmv1:assembly/asmv1:assemblyIdentity", appManifestNamespaces)
assemblyNode.Attributes("name").Value = appName & "-" & caller.Release.EnvironmentCode & ".dll"
'description
Dim descNode = appManifestXML.SelectSingleNode("/asmv1:assembly/asmv1:description", appManifestNamespaces)
descNode.InnerXml = appName & "-" & caller.Release.EnvironmentCode
'soluionid guid
Dim custNode = appManifestXML.SelectSingleNode("/asmv1:assembly/vstav3:addIn/vstav3:application/vstov4:customizations/vstov4:customization/vstov4:document", appManifestNamespaces)
Dim currentGUID = custNode.Attributes("solutionId").Value
Dim newGuid As String = String.Format("{0:x8}{1}", caller.Release.EnvironmentCode.ToLower.GetHashCode(), currentGUID.Substring(8))
custNode.Attributes("solutionId").Value = newGuid
appManifestXML.Save(appManifestFileInfo.FullName)
Return newGuid
End Function
Private Sub UpdateDeploymentManifestBasedOnTarget(caller As IReleaseExecutionCaller, appName As String, vstoFileInfo As IO.FileInfo)
Log.Write(Me.Name, String.Format("update the deployment manifest based on the target environment..."))
Dim vstoXML As New Xml.XmlDocument
Dim vstoManifestNamespaces As New Xml.XmlNamespaceManager(vstoXML.NameTable)
vstoManifestNamespaces.AddNamespace("asmv1", "urn:schemas-microsoft-com:asm.v1")
vstoManifestNamespaces.AddNamespace("asmv2", "urn:schemas-microsoft-com:asm.v2")
vstoXML.Load(vstoFileInfo.FullName)
'assemblyIdentity
Dim assemblyNode = vstoXML.SelectSingleNode("/asmv1:assembly/asmv1:assemblyIdentity", vstoManifestNamespaces)
assemblyNode.Attributes("name").Value = appName & "-" & caller.Release.EnvironmentCode & ".vsto"
'description
Dim descNode = vstoXML.SelectSingleNode("/asmv1:assembly/asmv1:description", vstoManifestNamespaces)
descNode.Attributes("asmv2:product").Value = appName & "-" & caller.Release.EnvironmentCode
'dependancy assemblyIdentity
Dim depAssmblyIdentityNode = vstoXML.SelectSingleNode("/asmv1:assembly/asmv2:dependency/asmv2:dependentAssembly/asmv2:assemblyIdentity", vstoManifestNamespaces)
depAssmblyIdentityNode.Attributes("name").Value = appName & "-" & caller.Release.EnvironmentCode & ".dll"
vstoXML.Save(vstoFileInfo.FullName)
End Sub