我需要在Amazon EC2实例上部署Web API服务。我已将AWS CodeDeploy配置为从GitHub存储库下载源并将它们放在目标EC2上。我已经在Windows Server 2012的服务器上安装了CodeDeploy Agent。此外,在成功下载源之后,我可以构建项目并发布,如果我在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命令?
答案 0 :(得分: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 = Release / p:OutputPath = deployment}