0

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 -> ()
        )
)
KCT
  • 287
  • 1
  • 10
  • Why would you not have this attribute from the beginning, why do you need fake to set this?I usually update the AssemblyInfo attributes with ones like `CLSCompliant`, `Copyright`, etc. – Alex M May 02 '16 at 20:39
  • I used ProjectScaffold for the build script and the AssemblyInfo task creates the whole file. But at least a good idea. I think there is an UpdateAttribute functions. I will check it. As far as I see the problem with the current CreateCSharpAssemblyInfo is that only strings can be used as values. Enums will require some code changes. – KCT May 04 '16 at 06:50

1 Answers1

1

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
)
Alex M
  • 2,410
  • 1
  • 24
  • 37
  • good idea. Just tested the UpdateAttributes function but I do get an error as soon as I have the ThemeAttribute in the AsseblyInfo (translated): "CS7036 Properties\AssemblyInfo.ca(10,12): There is no Argument that corresponds to the formal Parameter "genericDictionaryLocation" from "ThemeInfoAttribute.ThemInfoAtrribute(ResourceDictionaryLocation, ResourceDictionaryLocation)" The problem is that ThemeInfo uses Enums not strings [assembly: ThemeInfoAttribute(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] – KCT May 17 '16 at 06:59
  • I've tried and all is working fine. AssemblyInfo.cs contains the `[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]` prior running the `UpdateAssemblyInfo`. The later just updates with a needed values, for ex: `copyright = "Copyright " + company + DateTime.Now.ToString(" yyyy")` – Alex M May 18 '16 at 13:43
  • 1
    Thanks a lot. It works now. I reverted my changes tried it again. I just had to change the `CreateCSharpAssemblyInfo` (`CreateFSharpAssemblyInfo` `CreateVisualBasicAssemblyInfo` if needed) to `UpdateAttribute`. I add my code for reference in my question. I must have done something wrong before. I just noticed that the create methods add constants for `Version`and `InformationalVersion`. Those are not updated by this code. Thanks for your time helping me. – KCT May 19 '16 at 07:11