【发布时间】: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