Azure DevOps 中的 Service Fabric 生成的输出不正确

Posted

技术标签:

【中文标题】Azure DevOps 中的 Service Fabric 生成的输出不正确【英文标题】:Incorrect output from Service Fabric build in Azure DevOps 【发布时间】:2019-08-29 07:46:59 【问题描述】:

目前,我正在为我的服务结构应用程序创建 Azure DevOps 构建。在我的本地计算机上,构建、打包和发布步骤按预期工作。

但是当我在 Azure DevOps 上运行模板 Azure 服务结构构建时,生成的输出不正确。服务包的代码文件夹中不包含我的.exe,而是包含我的.sfproj 的根文件夹。

.sfproj 输出的构建和打包步骤中,我可以看到服务正在构建。

当前版本如下所示: - 使用 NuGet - NuGet 恢复 - 构建 .sln - 构建.sfproj - 复制文件 pdbs - 删除文件 *.pdbs - 更新服务结构清单 - 复制构建文件 - 发布工件

我已经尝试过的事情: - 在 DevOps 上实施服务结构模板构建。 - 尝试遵循互联网上的一些教程。 - 试图理解正在发生的事情以及它是如何发生的。 - 尝试运行本地 PowerShell 构建(可能我的文件有问题),此构建成功并输出正确。

我期望的构建输出:

>D:\TEMP\MYAPPLICATIONTYPE
>>ApplicationManifest.xml
>>>MyServiceManifest
>>>>ServiceManifest.xml  
>>>MyCode  
>>>> - MyServiceHost.exe   
>>>MyConfig  
>>>> - Settings.xml  
>>>MyData  
>>>> - init.dat'

我从构建中得到的输出:

>D:\TEMP\MYAPPLICATIONTYPE
>>ApplicationManifest.xml
>>>MyServiceManifest
>>>>ServiceManifest.xml  
>>>MyCode  
>>>> - ApplicationPackageRoot  
    - ApplicationParameters  
    - obj  
   - PublishProfiles  
   - Scripts  
    - Packages.config  
    - ServiceFabricApplication.sfproj  
    - ServiceFabricApplication.sfproj.log   
>>>MyConfig  
>>>> - Settings.xml  
>>>MyData  
>>>> - init.dat'

在发布步骤中出现以下本地发布中不会发生的错误:

`2019-04-08T14:31:51.9203463Z Service fabric SDK version: 2.4.164.9494.
2019-04-08T14:31:52.4143574Z ##[debug]INPUT_USEDIFFPACKAGE: 'false'
2019-04-08T14:31:52.5363270Z ##[debug]MAILPROCESSINGSERVICE_INSTANCECOUNT (empty)
2019-04-08T14:31:52.5383524Z ##[debug]INPUT_OVERWRITEBEHAVIOR: 'SameAppTypeAndVersion'
2019-04-08T14:31:53.5679860Z ##[debug]Join-Path "C:\Program Files\Microsoft Service Fabric\bin\fabric\fabric.code" "ServiceFabricServiceModel.xsd"
2019-04-08T14:31:53.5726035Z ##[debug]C:\Program Files\Microsoft Service Fabric\bin\fabric\fabric.code\ServiceFabricServiceModel.xsd
2019-04-08T14:31:53.5738046Z ##[debug]Length: 94
2019-04-08T14:31:53.5757439Z ##[debug]
2019-04-08T14:31:53.5780120Z ##[debug]Test-Path "C:\Program Files\Microsoft Service Fabric\bin\fabric\fabric.code\ServiceFabricServiceModel.xsd"
2019-04-08T14:31:53.5819217Z ##[debug]True
2019-04-08T14:31:53.5832941Z ##[debug]
2019-04-08T14:31:55.9628794Z ##[debug]System.Fabric.Management.ImageBuilder.FabricImageBuilderValidationException: Exception while parsing XML file: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml
2019-04-08T14:31:55.9641825Z ##[debug]FileName: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml ---> System.InvalidOperationException: There is an error in XML document (2, 254). ---> System.Xml.Schema.XmlSchemaValidationException: The 'ManifestId' attribute is not declared.
2019-04-08T14:31:55.9655413Z ##[debug]   at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity)
2019-04-08T14:31:55.9668097Z ##[debug]   at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(String code, String arg)
2019-04-08T14:31:55.9680818Z ##[debug]   at System.Xml.Schema.XmlSchemaValidator.ValidateAttribute(String lName, String ns, XmlValueGetter attributeValueGetter, String attributeStringValue, XmlSchemaInfo schemaInfo)
2019-04-08T14:31:55.9694803Z ##[debug]   at System.Xml.XsdValidatingReader.ValidateAttributes()
2019-04-08T14:31:55.9707640Z ##[debug]   at System.Xml.XsdValidatingReader.ProcessElementEvent()
2019-04-08T14:31:55.9846731Z ##[debug]   at System.Xml.XsdValidatingReader.Read()
2019-04-08T14:31:55.9860420Z ##[debug]   at System.Xml.XmlReader.MoveToContent()
2019-04-08T14:31:55.9876589Z ##[debug]   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read395_ApplicationManifest()
2019-04-08T14:31:55.9889383Z ##[debug]   --- End of inner exception stack trace ---
2019-04-08T14:31:55.9903452Z ##[debug]   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
2019-04-08T14:31:55.9919035Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.ReadXml[T](String fileName, XmlReader reader)
2019-04-08T14:31:55.9936054Z ##[debug]   --- End of inner exception stack trace ---
2019-04-08T14:31:55.9945480Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(Exception innerException, String type, String fileName, String format, Object[] args)
2019-04-08T14:31:55.9958172Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.ReadXml[T](String fileName, XmlReader reader)
2019-04-08T14:31:55.9971320Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.ReadXml[T](String fileName, XmlReaderSettings validatingXmlReaderSettings)
2019-04-08T14:31:55.9984222Z ##[debug]   at System.Fabric.Management.ImageBuilder.ApplicationProvisionOperation.<ParseApplicationPackageAsync>d__8.MoveNext()
2019-04-08T14:31:55.9996678Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2019-04-08T14:31:56.0009376Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2019-04-08T14:31:56.0022409Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2019-04-08T14:31:56.0035985Z ##[debug]   at System.Fabric.Management.ImageBuilder.ApplicationProvisionOperation.<ProvisionApplicationAsync>d__0.MoveNext()
2019-04-08T14:31:57.8717259Z ##[debug]SYSTEM_JOBID: '7541fd7f-879e-4baf-a7a6-9e527906c514'
2019-04-08T14:31:58.3025935Z ##[debug]Processed: ##vso[telemetry.publish area=TaskHub;feature=ServiceFabricDeploy]"OperationId":"TestApplicationPackage","ExceptionData":"System.Fabric.Management.ImageBuilder.FabricImageBuilderValidationException;System.InvalidOperationException;System.Xml.Schema.XmlSchemaValidationException;|D:\\a\\_tasks\\ServiceFabricDeploy_c6650aa0-185b-11e6-a47d-df93e7a34c64\\1.7.31\\ServiceFabricSDK\\Publish-NewServiceFabricApplication.ps1|243","JobId":"7541fd7f-879e-4baf-a7a6-9e527906c514","SDKVersion":"2.4.164.9494"
2019-04-08T14:31:58.8521847Z ##[debug]Leaving D:\a\_tasks\ServiceFabricDeploy_c6650aa0-185b-11e6-a47d-df93e7a34c64\1.7.31\deploy.ps1.
2019-04-08T14:31:58.8569063Z ##[debug]Caught exception from task script.
2019-04-08T14:31:58.8613132Z ##[debug]Error record:
2019-04-08T14:31:58.9458146Z ##[debug]Test-ServiceFabricApplicationPackage : Exception while parsing XML file: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml
2019-04-08T14:31:58.9475003Z ##[debug]FileName: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml
2019-04-08T14:31:58.9487449Z ##[debug]At D:\a\_tasks\ServiceFabricDeploy_c6650aa0-185b-11e6-a47d-df93e7a34c64\1.7.31\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:243 char:46
2019-04-08T14:31:58.9501612Z ##[debug]+ ... tionSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse)
2019-04-08T14:31:58.9516184Z ##[debug]+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-04-08T14:31:58.9544781Z ##[debug]    + CategoryInfo          : InvalidOperation: (:) [Test-ServiceFabricApplica    tionPackage], FabricImageBuilderValidationException
2019-04-08T14:31:58.9559184Z ##[debug]    + FullyQualifiedErrorId : TestApplicationPackageErrorId,Microsoft.ServiceF    abric.Powershell.TestApplicationPackage
2019-04-08T14:31:58.9575586Z ##[debug] 
2019-04-08T14:31:58.9596675Z ##[debug]Script stack trace:
2019-04-08T14:31:58.9642005Z ##[debug]at Publish-NewServiceFabricApplication, D:\a\_tasks\ServiceFabricDeploy_c6650aa0-185b-11e6-a47d-df93e7a34c64\1.7.31\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1: line 243
2019-04-08T14:31:58.9655696Z ##[debug]at <ScriptBlock>, D:\a\_tasks\ServiceFabricDeploy_c6650aa0-185b-11e6-a47d-df93e7a34c64\1.7.31\deploy.ps1: line 194
2019-04-08T14:31:58.9674225Z ##[debug]at <ScriptBlock>, <No file>: line 1
2019-04-08T14:31:58.9687438Z ##[debug]at <ScriptBlock>, <No file>: line 22
2019-04-08T14:31:58.9713344Z ##[debug]at <ScriptBlock>, <No file>: line 18
2019-04-08T14:31:58.9723271Z ##[debug]at <ScriptBlock>, <No file>: line 1
2019-04-08T14:31:58.9745709Z ##[debug]Exception:
2019-04-08T14:31:58.9793977Z ##[debug]System.Fabric.Management.ImageBuilder.FabricImageBuilderValidationException: Exception while parsing XML file: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml
2019-04-08T14:31:58.9805388Z ##[debug]FileName: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml ---> System.InvalidOperationException: There is an error in XML document (2, 254). ---> System.Xml.Schema.XmlSchemaValidationException: The 'ManifestId' attribute is not declared.
2019-04-08T14:31:58.9818107Z ##[debug]   at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity)
2019-04-08T14:31:58.9829274Z ##[debug]   at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(String code, String arg)
2019-04-08T14:31:58.9840639Z ##[debug]   at System.Xml.Schema.XmlSchemaValidator.ValidateAttribute(String lName, String ns, XmlValueGetter attributeValueGetter, String attributeStringValue, XmlSchemaInfo schemaInfo)
2019-04-08T14:31:58.9851940Z ##[debug]   at System.Xml.XsdValidatingReader.ValidateAttributes()
2019-04-08T14:31:58.9863424Z ##[debug]   at System.Xml.XsdValidatingReader.ProcessElementEvent()
2019-04-08T14:31:58.9877769Z ##[debug]   at System.Xml.XsdValidatingReader.Read()
2019-04-08T14:31:58.9891850Z ##[debug]   at System.Xml.XmlReader.MoveToContent()
2019-04-08T14:31:58.9906079Z ##[debug]   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read395_ApplicationManifest()
2019-04-08T14:31:58.9917176Z ##[debug]   --- End of inner exception stack trace ---
2019-04-08T14:31:58.9928302Z ##[debug]   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
2019-04-08T14:31:58.9939501Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.ReadXml[T](String fileName, XmlReader reader)
2019-04-08T14:31:58.9950819Z ##[debug]   --- End of inner exception stack trace ---
2019-04-08T14:31:58.9962116Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(Exception innerException, String type, String fileName, String format, Object[] args)
2019-04-08T14:31:58.9973510Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.ReadXml[T](String fileName, XmlReader reader)
2019-04-08T14:31:58.9984837Z ##[debug]   at System.Fabric.Management.ImageBuilder.ImageBuilderUtility.ReadXml[T](String fileName, XmlReaderSettings validatingXmlReaderSettings)
2019-04-08T14:31:58.9998358Z ##[debug]   at System.Fabric.Management.ImageBuilder.ApplicationProvisionOperation.<ParseApplicationPackageAsync>d__8.MoveNext()
2019-04-08T14:31:59.0007662Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2019-04-08T14:31:59.0020745Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2019-04-08T14:31:59.0032029Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2019-04-08T14:31:59.0045270Z ##[debug]   at System.Fabric.Management.ImageBuilder.ApplicationProvisionOperation.<ProvisionApplicationAsync>d__0.MoveNext()
2019-04-08T14:31:59.0363118Z ##[error]Exception while parsing XML file: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml
FileName: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml
2019-04-08T14:31:59.0371868Z ##[debug]Processed: ##vso[task.logissue type=error]Exception while parsing XML file: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml%0D%0AFileName: C:\Users\VssAdministrator\AppData\Local\Temp\TestApplicationPackage_31174153637\r5wofi1j.xyh\applicationpackage\ApplicationManifest.xml
2019-04-08T14:31:59.0373492Z ##[debug]Processed: ##vso[task.complete result=Failed]`

【问题讨论】:

你用什么MSBuild Arguments 来构建.sfproj.sln 对于.sln,使用以下参数:/p:RunInBuild=true 对于.sfproj,使用以下参数:/t:Package /p:PackageLocation=$(build.artifactstagingdirectory)\Application\applicationpackage 【参考方案1】:

如果您将 BuildPlatform 设置为 Any CPUx32 在 Azure DevOps 上为 .sln.sfproj 将其更改为 x64 并且它应该可以工作。

【讨论】:

我无法将 .sln 更改为 x64,因为它包含多个需要为 AnyCPU.csproj。我是否需要专门为 Service Fabric 应用程序创建单独的构建? 不,您不需要创建单独的构建。如果您无法将.sln build 更改为x64,则仅更改.sfproj build。 .sfproj 在解决方案的其余部分中具有依赖关系,这使得仅更改 .sfproj 变得困难我目前正在尝试进行此设置,但目前我不断收到错误.当我得到一个成功的构建错误后回到这里。 您必须以 64 位构建它,否则它将无法工作,并且您会遇到类似这些奇怪的错误。【参考方案2】:

好的,构建问题已经解决了。

不可能将整个解决方案重写为 x64 或针对 x64 构建服务。我做的事情如下:

    构建.sfproj 将项目工件复制到暂存目录。 从暂存工件的application/code 文件夹中删除所有项目。 独立于“.sfproj”构建服务。 将服务构建输出复制到.sfproj 代码包中。

接下来,对于发布问题,问题是另一个.csproj 使用了hosted 代理。 .sfproj 出于某种原因需要 hosted vs2017 代理。只需添加使用此代理的第二个代理阶段即可修复版本。

我希望这可以帮助遇到与我相同问题的人。

【讨论】:

以上是关于Azure DevOps 中的 Service Fabric 生成的输出不正确的主要内容,如果未能解决你的问题,请参考以下文章

Azure DevOps 中的 Service Fabric 生成的输出不正确

isUpgrade 设置如何影响 Azure DevOps 中 Service Fabric 应用程序部署任务中的部署过程

sh 检查Azure DevOps Service Connect是否可访问

使用 Azure DevOps 部署具有不同名称的 Service Fabric 服务

Azure Devops 无法连接到 Service Fabric 群集

Service Fabric Guest .Net Core 3.1 API exe 的 Azure DevOps 构建管道在创建包时失败