简体   繁体   English

用PowerShell编写的MyGet预构建脚本?

[英]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! 所有示例均以类批编写!

  • Are there any resources online that I missed ? 我错过了在线资源吗?
  • What is the proper (official/most simple) way, in PowerShell, to build and package a library with MyGet? 在PowerShell中使用MyGet构建和打包库的正确(正式/最简单)方法是什么?

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.

相关问题 Powershell Pre-Build脚本从msbuild失败 - Powershell Pre-Build script failing from msbuild 在预构建事件中执行PowerShell脚本失败 - Executing PowerShell script as pre-build event fails TFS 2013-从预构建PowerShell脚本更新MSBuild参数 - TFS 2013 - Update MSBuild Parameters from pre-build PowerShell script 我可以使用“ pre-build”脚本来决定是构建还是跳过项目吗? - Can I have a `pre-build` script decide whether to build or skip the project? 由于发生预生成和生成后事件,Visual Studio 2012的生成缓慢 - Visual Studio 2012 slow build because of pre-build and post-build events 在Visual Studio Team Services中运行预构建脚本以进行Azure连续部署构建过程 - Running pre-build scripts in Visual Studio Team Services for Azure Continuous Deployment build process 为什么 Visual Studio 中的所有预生成或生成后事件都失败并显示退出代码 1? - Why do all Pre-build or Post-build events in Visual Studio fail with exit code 1? 使用PowerShell驱动YUI Compressor并将语法错误作为Visual Studios预生成脚本写入.txt文件 - Drive YUI Compressor with PowerShell and Write Syntax Errors to .txt file as a Visual Studios Pre Build Script post-build powershell脚本 - Post-build powershell script 用于构建 TFS 定义的 PowerShell 脚本 - PowerShell Script to Build TFS Definition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM