如何使用 FAKE 将 ThemeInfo 属性添加到 AssemblyInfo.cs?

How to add ThemeInfo attribute into AssemblyInfo.cs with FAKE?

对于我的自定义控件,我需要将以下属性添加到 AssemblyInfo.cs:

using System.Windows;

[assembly: ThemeInfo(ResourceDictionaryLocation.None,     
 ResourceDictionaryLocation.SourceAssembly 
 )]

是否可以通过 FAKE 中的可用选项以某种方式实现,或者是否需要其他属性实现?

解法: 正如 AlexM 所提到的,UpdateAttribute 是 ThemeAttribute 已经在 AssemblyInfo 中的关键。这里有机会使用 ProjectScaffold 的默认值作为参考的最终代码:

Target "AssemblyInfo" (fun _ ->
    let getAssemblyInfoAttributes projectName =
        [ Attribute.Title (projectName)
          Attribute.Product project
          Attribute.Description summary
          Attribute.Version release.AssemblyVersion
          Attribute.FileVersion release.AssemblyVersion
         ]

    let getProjectDetails projectPath =
        let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
        ( projectPath,
          projectName,
          System.IO.Path.GetDirectoryName(projectPath),
          (getAssemblyInfoAttributes projectName)
        )

    !! "src/**/*.??proj"
    |> Seq.map getProjectDetails
    |> Seq.iter (fun (projFileName, projectName, folderName, attributes) ->
        match projFileName with
        | Fsproj -> UpdateAttributes (folderName </> "AssemblyInfo.fs") attributes
        | Csproj -> UpdateAttributes ((folderName </> "Properties") </> "AssemblyInfo.cs") attributes
        | Vbproj -> UpdateAttributes ((folderName </> "My Project") </> "AssemblyInfo.vb") attributes
        | Shproj -> ()
        )
)

解决这个问题的另一种方法是在您的项目中从一开始就有一个 AssemblyInfo.cs,任何附加属性如 ThemeInfo。在你的假脚本中有一个目标来更新公共属性:

Target "UpdateAssemblyInfo" (fun _ -> 
    let csharpProjectDirs =
        !! "**/**/*.csproj"
        |> Seq.map (directory >> directoryInfo)

    let sharedAttributes =
        [   Attribute.Description description
            Attribute.Product product
            Attribute.Copyright copyright
            Attribute.Company company
            Attribute.Version version
            Attribute.FileVersion version
            ]
    let applyAssemblyInfo (projDir:DirectoryInfo) =  
        let assemblyInfoFile = projDir.FullName @@ "Properties/AssemblyInfo.cs"
        let attributes = (Attribute.Title projDir.Name) :: sharedAttributes

        UpdateAttributes
            assemblyInfoFile
            attributes

    csharpProjectDirs |> Seq.iter applyAssemblyInfo
)