I'm taking Visual Studio 2017 RC for a test drive, and I've hit a stumbling block.
My project contains an ASP.NET Core Web project, and two portable F# libraries (Profile 259). The web project references these libraries, and I would like in the future to add Xamarin Forms projects which also reference the same Profile 259 libraries.
I would also like to have a localisation resources file (maybe in its own shared project), which can be read by all of the projects in my solution. In Visual Studio 2015, I achieved this by creating a portable C# project and adding the relevant resx
file.
In Visual Studio 2017, I can't add a portable C# class library. When I attempt to do so, it serves up a modal dialog, which does not accept any of the options it presents me with:
I can, however, add a Xamarin Forms library:
and although this references Xamarin Forms libraries I'm not really interested in, it can at least be added, and I can add my localisation file LocalisedStrings.resx
to the project.
However, even though I've changed the access modifier to "Public" in the resx
file, it is not getting read from my F# library. The code
module Locales =
let [<Literal>] private Gender = "Gender"
let private localisedStringsProperties = typeof<LocalisedStrings>.GetTypeInfo().DeclaredProperties
let GetStringDictionary(predicate) = localisedStringsProperties |> Seq.filter predicate |> Seq.map (fun p -> (p.Name, p.GetMethod.Invoke(null, [||]).ToString())) |> dict
let GetGenders() = GetStringDictionary(fun p -> p.Name.StartsWith(Gender) && p.Name.Length > Gender.Length)
let GetValues(keys) =
let values = GetStringDictionary(fun p -> keys |> Array.exists(fun key -> key = p.Name))
let evaluate key =
match values.ContainsKey key with
| true -> values.[key]
| false -> key
keys |> Array.map evaluate
let GetValue(key) = GetValues([|key|]).[0]
does not recognise either the namespace or the class LocalisedStrings
.
QUESTIONS
- Is there another way to do localisation from a portable F# library? I can't add
resx
files directly, which is why I used the portable C# library in my 2015 project. However, if there is a more F# way to do it, I am open to using that. - Is the fact that I can't add a portable C# project a Release Candidate bug, or has that project type been deprecated?
- Why are the
LocalisedStrings
class and namespace not being picked up by my F# library, even though the project reference has been added successfully, and theresx
access modifier has been changed to public?
UPDATE: Question 2 has been answered. That is a PEBKAC issue: I simply had to check more than one checkbox. In this case, I needed to check off all of the options that were included in Profile 259 (.NET Framework 4,5, ASP.NET Core 1.0, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8). However, Questions 1 and 3 still stand.