【问题标题】:How to handle post-build events in an Azure pipeline?如何处理 Azure 管道中的构建后事件?
【发布时间】:2021-01-17 21:02:48
【问题描述】:

我可以在本地构建解决方案,并且在一个项目中我有构建后事件:

xcopy "$(SolutionDir)pluginfolder\bin\Debug\net48\pluginname.*" "$(TargetDir)" /Y

我这样做是因为目标项目没有对插件项目的引用。

现在我正在尝试迁移到 Azure 管道。我创建了一个 MSBuild 任务,它只构建目标项目而不是完整的解决方案,在自托管代理中运行时出现以下错误:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5266,5):错误 MSB3073:命令“xcopy” Undefinedpluginfolder\bin\Debug\net48\pluginname.*" "C:\agent_work\5\s\myproj\bin" /Y 以代码 4 结尾。

解决此问题的最佳方法是什么?

【问题讨论】:

    标签: visual-studio azure-devops


    【解决方案1】:
    "Undefinedpluginfolder\bin\Debug\net48\pluginname.*"
    

    $(SolutionDir) 被识别为未定义,这是因为 msbuild 在构建单个项目时不了解解决方案。

    作为解决方法,您可以在 PostBuild 事件的脚本上方插入以下脚本。比如:

      <PropertyGroup>
        <ProjectFolder>$([System.IO.Directory]::GetParent($(ProjectDir)))</ProjectFolder>
        <MySolutionDir>$([System.IO.Directory]::GetParent($(ProjectFolder)))\</MySolutionDir>
        It's recommended to add my script and PostBuildEvent in same propertyGroup
        <PostBuildEvent>echo $(MySolutionDir)</PostBuildEvent> 
      </PropertyGroup>
    

    命令行:

    xcopy "$(MySolutionDir)pluginfolder\bin\Debug\net48\pluginname.*" "$(TargetDir)" /Y
    

    你可以参考这个ticket有类似的问题。

    【讨论】:

      猜你喜欢
      • 2021-11-04
      • 1970-01-01
      • 2020-05-03
      • 2020-01-01
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 2021-01-21
      • 2020-09-09
      相关资源
      最近更新 更多