2016-06-09 22 views
0

我需要在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命令?

+0

您確定腳本在CodeDeploy之外手動運行時工作嗎? –

回答

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}

相關問題