[英]MyGet pre-build script written in PowerShell?
我的預構建腳本最初是.bat。 添加功能以生成版本號時,我是在PowerShell中編寫的(我真的不喜歡批處理)。 因此,我嘗試將整個預構建腳本轉換為PowerShell,但遇到了麻煩。
## pre-build.ps1
function SetPackageVersion
{
if(gitversion /output json /showvariable PreReleaseTagWithDash)
{
##myget[buildNumber "$(gitversion /output json /showvariable Major).$(gitversion /output json /showvariable Minor).$(gitversion /output json /showvariable CommitsSinceVersionSource)-$(gitversion /output json /showvariable PreReleaseTagWithDash)"]
}
else
{
##myget[buildNumber "$(gitversion /output json /showvariable Major).$(gitversion /output json /showvariable Minor).$(gitversion /output json /showvariable CommitsSinceVersionSource)"]
}
GitVersion /updateassemblyinfo true
}
set config=Release
SetPackageVersion
## Package restore
NuGet restore Library\packages.config -OutputDirectory %cd%\packages -NonInteractive
Build "%programfiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" MakeMeATable.sln /p:Configuration="%config%" /m /v:M /fl /flp:LogFile=msbuild.log;Verbosity=Normal /nr:false
## Package
mkdir Build
nuget pack "Library\MakeMeATable.csproj" -symbols -o Build -p Configuration=%config% %version%
我在MyGet構建日志中得到這些錯誤(以及其他錯誤)
Build : The term 'Build' 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 D:\temp\fcd4ee1\pre-build.ps1:24 char:1 + Build "%programfiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" MakeMeATable ... + ~~~~~ + CategoryInfo : ObjectNotFound: (Build:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException The term 'Verbosity=Normal' 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 D:\temp\fcd4ee1\pre-build.ps1:24 char:140 + ... onfig%" /m /v:M /fl /flp:LogFile=msbuild.log;Verbosity=Normal /nr:fal ... + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Verbosity=Normal:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
我不明白為什么找不到有關為MyGet創建PowerShell預構建腳本的方法的任何好的參考資料? 所有示例均以類批編寫!
我沒有MyGet的經驗,但是a可以給您一些有關錯誤和代碼的建議。
生成:術語“生成”不被視為cmdlet,函數,腳本文件或可運行程序的名稱。
解釋器無法將Build
識別為命令。 它在哪里定義? 是別名嗎? 包括在某處? 可執行文件位於其他路徑? 同樣,您的命令行看起來並不是一開始就需要的。 嘗試用呼叫運算符 ( &
)替換它。
術語'Verbosity = Normal'不被視為cmdlet,函數,腳本文件或可運行程序的名稱。
PowerShell中的分號與和號的含義相同:它是菊花鏈命令的運算符。 因此,PowerShell嘗試將Verbosity=Normal
作為新語句執行,而不是將其作為/flp
參數的一部分來處理。 將參數放在引號中可以避免這種情況。
另外,您不能在PowerShell中使用CMD內置變量( %cd%
)或常規的批處理變量語法( %var%
)。 %cd%
的等效項是$pwd
(更具體地說是$pwd.Path
), 變量的常規語法是$var
或${var}
(如果變量名稱包含空格等非單詞字符,則必須使用后者;括號等)。
將語句更改為如下所示:
& "${ProgramFiles(x86)}\\MSBuild\\14.0\\Bin\\MSBuild.exe" MakeMeATable.sln "/p:Configuration=$config" /m /v:M /fl "/flp:LogFile=msbuild.log;Verbosity=Normal" /nr:false
它應該工作。 更好的是,使用splatting傳遞參數:
$params = 'MakeMeATable.sln', "/p:Configuration=$config", '/m', '/v:M', '/fl', '/flp:LogFile=msbuild.log;Verbosity=Normal', '/nr:false' & "${ProgramFiles(x86)}\\MSBuild\\14.0\\Bin\\MSBuild.exe" @params
PowerShell和批處理中的變量分配不同。 雖然set config=Release
不會產生錯誤(因為set
是cmdlet Set-Variable
的內置別名),但它沒有達到您的期望。 而不是使用變量Release
定義變量config
,而是使用空值定義變量config=Release
。
更改
set config=Release
至
$config = 'Release'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.