我需要在Amazon EC2實例上部署Web API服務。我已經配置AWS CodeDeploy以從GitHub存儲庫下載源並將它們放在目標EC2上。我已經在Windows Server 2012的服務器上安裝了CodeDeploy代理。此外,在成功下載源代碼後,我可以構建項目併發布,如果在PowerShell控制檯(運行BuildApp.ps1)中手動執行操作。通過AWS CodeDeploy代理在PowerShell中執行msbuild
我需要做的是通過在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"
但是,如果我執行發佈使用亞馬遜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之外手動運行時工作嗎? –