KCT
KCT

Reputation: 287

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

For my custom control I need to add the following Attribute to the AssemblyInfo.cs:

using System.Windows;

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

Is it somehow possible with the available options in FAKE or does it need another attribute implementation?

Solution: As mentioned by AlexM UpdateAttribute is the key where the ThemeAttribute is already in the AssemblyInfo. Here the chance final code for reference by using the defaults of 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 -> ()
        )
)

Upvotes: 0

Views: 535

Answers (1)

Alex M
Alex M

Reputation: 2548

The alternative way of approaching this is to have an AssemblyInfo.cs in your project(s) from the start with any additional attribute as ThemeInfo. Have a target in your fake script to update common attributes:

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
)

Upvotes: 1

Related Questions