fsprojects / FsXaml

F# Tools for working with XAML Projects
http://fsprojects.github.io/FsXaml/
MIT License
171 stars 48 forks source link

Avoiding exception in case when "LogicalName" wasn't provided for EmbeddedResource. #79

Open FoggyFinder opened 5 years ago

FoggyFinder commented 5 years ago

Right now it's neccessary to specify LogicalName for EmbeddedResource like this:

<LogicalName>MainWindow.xaml</LogicalName>

I think it will be better to allow user skip this step or at least make it clearly what's went wrong. Current exception message just suggest checking that file is marked as Resource.

So, in function getEmbeddedResourceStream instead of:

let resourceName = 
    ass.GetManifestResourceNames()
    |> Array.tryFind (fun n -> n.ToLowerInvariant().Trim() = file.ToLowerInvariant().Trim())

use

let file' = file.ToLowerInvariant().Trim()
let resourceName = 
    ass.GetManifestResourceNames()
    |> Array.tryFind
           (fun n ->
               let n' = n.ToLowerInvariant().Trim()
               n' = file' || n' = ass.GetName().Name.ToLowerInvariant().Trim() + "." + file')
ReedCopsey commented 5 years ago

Making this work with Resource and EmbeddedResource makes sense - I'm open to making this change provided it's tested and backwards compatible.

FoggyFinder commented 5 years ago

Initially I've thought about just minimal changes - one additional condition for name checking