【问题标题】:Execute msbuild in PowerShell via AWS CodeDeploy Agent通过 AWS CodeDeploy 代理在 PowerShell 中执行 msbuild
【发布时间】:2016-06-09 15:41:17
【问题描述】:

我需要在 Amazon EC2 实例上部署 Web API 服务。我已将 AWS CodeDeploy 配置为从 GitHub 存储库下载源并将它们放在目标 EC2 上。我已经在装有 Windows Server 2012 的服务器上安装了 CodeDeploy 代理。此外,在成功下载源代码后,我可以构建项目并发布,如果我在 PowerShell 控制台中手动执行(运行 BuildApp.ps1)。

我需要做的是通过在 CodeDeploy 代理工作期间自动运行的 PowerShell 脚本来完成项目的构建和发布。

我已经配置了appspec.yml文件,内容如下:

version: 0.0
os: windows
files:
  - source: /My-Project/
    destination: C:\inetpub\my-project-dev\src
hooks:
  AfterInstall:
    - location: .\BuildApp.ps1

BuildApp.ps1 有以下内容:

#Restore Nuget packages nuget install C:\inetpub\my-project-dev\src\RestApi\packages.config -OutputDirectory .\packages

Set-Location C:\inetpub\my-project-dev\src\RestApi

#Build the project msbuild RestApi.csproj /p:Configuration=Release /p:OutputPath="publish"

但是,如果我使用 Amazon CodeDeploy 控制台执行发布,日志文件会显示如下错误:

nuget : The term 'nuget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\ProgramData\Amazon\CodeDeploy\ca6544b1-d2cb-4a81-86c0-68ae0f60764b\d-A2V2JCQ3G\deployment-archive\BuildApp.ps1:3 char:1
nuget install C:\inetpub\my-project-dev\src\RestApi\packages.config

msbuild : The term 'msbuild' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\ProgramData\Amazon\CodeDeploy\ca6544b1-d2cb-4a81-86c0-68ae0f60764b\d-A2V2JCQ3G\deployment-archive\BuildApp.ps1:8 char:1
msbuild RestApi.csproj /p:Configuration=Release /p:OutputPath="publish"

什么原因导致 PowerShell 找不到 nuget 和 msbuild 命令?

【问题讨论】:

  • 您确定脚本在 CodeDeploy 之外手动运行时有效吗?

标签: powershell msbuild aws-code-deploy


【解决方案1】:

问题在于尝试调用 64 位版本的 PowerShell 命令 (msbuild),而 Amazon CodeDeploy Windows 实用程序是 32 位程序并执行 32 位 msbuild 命令。因此,我必须指定 msbuild.exe 的绝对路径。

C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -Command {&"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" MyProject.csproj /p:Configuration =发布/p:OutputPath=部署}

【讨论】:

    猜你喜欢
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    相关资源
    最近更新 更多