[英]MyGet pre-build script written in PowerShell?
My pre-build script originally was a .bat. 我的预构建脚本最初是.bat。 When I added the functionality to generate the version number, I wrote it in PowerShell (I really don't like batch).
添加功能以生成版本号时,我是在PowerShell中编写的(我真的不喜欢批处理)。 So I tried to convert the whole pre-build script into PowerShell but I'm running into difficulties.
因此,我尝试将整个预构建脚本转换为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%
I get these errors in the MyGet build log (among others) 我在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
I do not understand why I can't find any good reference about the way to create a PowerShell prebuild script for MyGet? 我不明白为什么找不到有关为MyGet创建PowerShell预构建脚本的方法的任何好的参考资料? All the examples are written in class batch!
所有示例均以类批编写!
I don't have experience with MyGet, but a can give you some advice on the errors and your code in general. 我没有MyGet的经验,但是a可以给您一些有关错误和代码的建议。
Build : The term 'Build' is not recognized as the name of a cmdlet, function, script file, or operable program.
生成:术语“生成”不被视为cmdlet,函数,脚本文件或可运行程序的名称。
The interpreter doesn't recognize Build
as a command. 解释器无法将
Build
识别为命令。 Where is it defined? 它在哪里定义? Is it an alias?
是别名吗? Included somewhere?
包括在某处? An executable in a different path?
可执行文件位于其他路径? Also, your commandline doesn't look like it would be required in the first place.
同样,您的命令行看起来并不是一开始就需要的。 Try replacing it with the call operator (
&
). 尝试用呼叫运算符 (
&
)替换它。
The term 'Verbosity=Normal' is not recognized as the name of a cmdlet, function, script file, or operable program.
术语'Verbosity = Normal'不被视为cmdlet,函数,脚本文件或可运行程序的名称。
The semicolon in PowerShell has the same meaning as the ampersand in batch: it's the operator for daisy-chaining commands. PowerShell中的分号与和号的含义相同:它是菊花链命令的运算符。 Because of that PowerShell tries to execute
Verbosity=Normal
as a new statement instead of handling it as part of the argument for the parameter /flp
. 因此,PowerShell尝试将
Verbosity=Normal
作为新语句执行,而不是将其作为/flp
参数的一部分来处理。 Put the parameter in quotes to avoid this. 将参数放在引号中可以避免这种情况。
Also, you cannot use CMD builtin variables ( %cd%
) or batch variable syntax in general ( %var%
) in PowerShell. 另外,您不能在PowerShell中使用CMD内置变量(
%cd%
)或常规的批处理变量语法( %var%
)。 The equivalent for %cd%
is $pwd
(more specifically $pwd.Path
), and the general syntax for variables is $var
or ${var}
(the latter must be used if the variable name contains non-word characters like spaces, parentheses, etc.). %cd%
的等效项是$pwd
(更具体地说是$pwd.Path
), 变量的常规语法是$var
或${var}
(如果变量名称包含空格等非单词字符,则必须使用后者;括号等)。
Change the statement to something like this: 将语句更改为如下所示:
& "${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
and it should work. 它应该工作。 Better yet, use splatting for passing the arguments:
更好的是,使用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
Variable assignments in PowerShell and batch are different. PowerShell和批处理中的变量分配不同。 While
set config=Release
won't produce an error (because set
is a builtin alias for the cmdlet Set-Variable
) it doesn't do what you expect. 虽然
set config=Release
不会产生错误(因为set
是cmdlet Set-Variable
的内置别名),但它没有达到您的期望。 Instead of defining a variable config
with the value Release
it defines a variable config=Release
with an empty value. 而不是使用变量
Release
定义变量config
,而是使用空值定义变量config=Release
。
Change 更改
set config=Release
to 至
$config = 'Release'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.