简体   繁体   English

无法理解FAKE代码: - FAKE F#MAKE

[英]Not able to understand FAKE Code : - FAKE F#MAKE

I have a sample script , and I am not able to understand a piece of code from that file , here is the code: 我有一个示例脚本,我无法理解该文件中的一段代码,这里是代码:

Target "Package1" (fun _ ->
  NuGet (fun p ->
    { p with
      OutputPath = DeployDir
      ReleaseNotes = ReleaseNote
      WorkingDir = BuildDir
      Publish = false
      Version = PackageVersion
      Files = [
        (@"*.dll", Some "lib", None)
        (@"*.pdb", Some "lib",  None)
      ]
    })
    "src/Client/Project.Client.nuspec"
)

and this target's order is last . 而且这个目标的顺序是最后的。 So what is the purpose of using this target. 那么使用这个目标的目的是什么呢? and what is last line doing src/Project.Client/Project.Client.nuspec .If anyone can explain this in details , that would be really helpful. 什么是最后一行做src/Project.Client/Project.Client.nuspec 。如果有人能详细解释这一点,那将非常有帮助。

Look at the indentation. 看看缩进。 The "src/Client/Project.Client.nuspec" string is indented further than NuGet , because it's one of the parameters to the NuGet function (which wants two parameters). "src/Client/Project.Client.nuspec"字符串比缩进进一步 NuGet ,因为它的参数传递到之一NuGet功能(这要两个参数)。 Here's another way this target could have been written, with the same effect but different indentation: 这是编写此目标的另一种方式,具有相同的效果但不同的缩进:

Target "Package1" (fun _ ->
  NuGet 
    (fun p -> { p with OutputPath = DeployDir
                       ReleaseNotes = ReleaseNote
                       WorkingDir = BuildDir
                       Publish = false
                       Version = PackageVersion
                       Files = [
                         (@"*.dll", Some "lib", None)
                         (@"*.pdb", Some "lib",  None)
                       ]
              }
    )
    "src/Client/Project.Client.nuspec"
)

Or to make it even clearer: 或者让它更清晰:

let nuGetParameterFunction = 
    (fun p -> { p with OutputPath = DeployDir
                       ReleaseNotes = ReleaseNote
                       WorkingDir = BuildDir
                       Publish = false
                       Version = PackageVersion
                       Files = [
                         (@"*.dll", Some "lib", None)
                         (@"*.pdb", Some "lib",  None)
                       ]
              }
    )

Target "Package1" (fun _ ->
  NuGet nuGetParameterFunction "src/Client/Project.Client.nuspec"
)

Both of these snippets do exactly the same thing as the snippet you asked about. 这两个片段与您询问的片段完全相同。 It's just that in these, it's a little more obvious that the NuGet function takes two parameters. 只是在这些中, NuGet函数采用两个参数更为明显。

If you look at the documentation for NuGetHelper the signature for NuGet function is setParams:(NuGetParams -> NuGetParams) -> nuspecOrProjectFile:string -> unit . 如果查看NuGetHelper的文档,NuGet函数的签名是setParams:(NuGetParams -> NuGetParams) -> nuspecOrProjectFile:string -> unit

This means that the function takes a setParams function that creates a new set of NuGetParams from the default set of NuGetParams . 这意味着该功能需要一个setParams创建一套新的功能NuGetParams从默认设置NuGetParams And a path where to write the resulting nuspec file. 以及写入生成的nuspec文件的路径。

In your example the setParams function is defined as (my comments): 在您的示例中, setParams函数定义为(我的注释):

fun p ->
    { p with                      // p is the default NuGetParams
      OutputPath = DeployDir      // set OutputPath from FAKE properties
      ReleaseNotes = ReleaseNote  // Set ReleaseNotes to ReleaseNote (from FAKE)
      WorkingDir = BuildDir       // Set WorkingDir from FAKE properties
      Publish = false             // Do not publish to NuGet.org
      Version = PackageVersion    // Set Version number
      Files = [                   // Put these files from WorkingDir into the package
        (@"*.dll", Some "lib", None)
        (@"*.pdb", Some "lib",  None)
      ]
    })

The reason that Target "Package1" is the last target is to ensure that all values for the setParams value are valid. Target "Package1"是最后一个目标的原因是确保setParams值的所有值都有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM