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

时间:2016-04-28 12:07:58

标签: f# assemblyinfo f#-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 -> ()
        )
)

1 个答案:

答案 0 :(得分:1)

接近此方法的另一种方法是在项目中从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 ) 。在假脚本中有一个目标来更新常用属性:

<Persons>
    <person>
        <id>XA123</id>
        <first_name>Adam</first_name>
        <last_name>John</last_name>
        <phone>01-12322222</phone>
    </person>
    <person>
        <id>XA7777</id>
        <first_name>Anna</first_name>
        <last_name>Watson</last_name>
        <relationship>
            <type>Friends</type>
            <to>XA123</to>
        </relationship>
    </person>
</Persons>