{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/3607","repository_url":"https://api.github.com/repos/Microsoft/visualfsharp","labels_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/3607/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/3607/comments","events_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/3607/events","html_url":"https://github.com/Microsoft/visualfsharp/pull/3607","id":258956361,"number":3607,"title":"Generate source for .resx files on build.","user":{"login":"brettfo","id":926281,"avatar_url":"https://avatars0.githubusercontent.com/u/926281?v=4","gravatar_id":"","url":"https://api.github.com/users/brettfo","html_url":"https://github.com/brettfo","followers_url":"https://api.github.com/users/brettfo/followers","following_url":"https://api.github.com/users/brettfo/following{/other_user}","gists_url":"https://api.github.com/users/brettfo/gists{/gist_id}","starred_url":"https://api.github.com/users/brettfo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettfo/subscriptions","organizations_url":"https://api.github.com/users/brettfo/orgs","repos_url":"https://api.github.com/users/brettfo/repos","events_url":"https://api.github.com/users/brettfo/events{/privacy}","received_events_url":"https://api.github.com/users/brettfo/received_events","type":"User","site_admin":false},"labels":[{"id":192460618,"url":"https://api.github.com/repos/Microsoft/visualfsharp/labels/cla-not-required","name":"cla-not-required","color":"90EE90","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-19T20:38:48Z","updated_at":"2017-09-21T17:25:53Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/pulls/3607","html_url":"https://github.com/Microsoft/visualfsharp/pull/3607","diff_url":"https://github.com/Microsoft/visualfsharp/pull/3607.diff","patch_url":"https://github.com/Microsoft/visualfsharp/pull/3607.patch"},"body":"This PR auto-generates the code necessary to access resources from a `.resx` file automatically during build.  Included in this is the deletion of a lot of manually maintained code.\r\n\r\nThis is added as build targets/tasks in `FSharp.Build` for two reasons:\r\n\r\n1.  Updating `resgen.exe` would take forever for it to find its way to F# builds.\r\n2.  I want this to run on CoreCLR-based projects, especially during `dotnet build`.\r\n\r\nThere are a few items to point out:\r\n\r\n1.  I didn't want to break any existing code by generating source files where they weren't before so I've gated source generation on the `GenerateSource` metadata which can be specified in one of two ways: inline `<EmbeddedResource Include=\"file.resx\" GenerateSource=\"true\" />`, or as a child element: `<EmbeddedResource Include=\"file.resx\"><GenerateSource>true</GenerateSource></EmbeddedResource>`.  Where possible I've used the first attribute-based method, but some projects built with xbuild on Linux don't allow extra attributes, so for those projects I've resorted to the element approach.\r\n2.  To avoid issues with file naming I honor the `GeneratedModuleName` metadata when supplied, otherwise I do what resgen does for C#/VB and use the file name as the base.  This is particularly useful in `FSharp.Core` where I want the generated code to continue to be named `Microsoft.FSharp.Core.SR` but can't rename the resource file to `Microsoft.FSharp.Core.SR.resx` because that's incorrectly determined to be Serbian resources (`\"sr\"`).\r\n3.  Generated resources are exposed as functions with the signature `unit -> string`, but this doesn't work for `FSharp.Core` because the type `unit` hasn't been defined by the time some of the strings are needed.  Attempting to move the definition of `Unit/unit` to `prim-types-prelude.fs/fsi` was unsuccessful due to type matching (`:?` operator) not being defined yet which is needed in the `.Equals()` overload.  The solution to this was to allow generation of code nearly identical to the deleted `SR.fs` by defining string constants instead of functions and manually passing those through `.GetString()`.  This is handled by the `GenerateLegacyCode` metadata which defaults to `false`.\r\n4.  Related to the above item, when generating legacy code, wherever possible I've added the `[<Literal>]` attribute because that's needed in some of the VS-specific resources, but again this can't be done in `FSharp.Core` because that attribute doesn't yet exist, so this is controlled by the `GenerateLiterals` metadata which defaults to `true`.\r\n\r\nNot implemented in this PR:\r\n1.  Proper signature detection for non-string resources.  For an example see [this file](https://github.com/Microsoft/visualfsharp/blob/194fa62b3ec2fc228af0d491c85bb413f0802fdb/vsintegration/src/FSharp.ProjectSystem.FSharp/VSPackage.resx#L218).  Currently I generate a function with the signature `unit -> obj`, but eventually it would be nice to parse the `type` attribute and the content of the `<value>` element to properly generate a function with the signature `unit -> System.Drawing.Bitmap`."},"comment":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/comments/331225462","html_url":"https://github.com/Microsoft/visualfsharp/pull/3607#issuecomment-331225462","issue_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/3607","id":331225462,"user":{"login":"brettfo","id":926281,"avatar_url":"https://avatars0.githubusercontent.com/u/926281?v=4","gravatar_id":"","url":"https://api.github.com/users/brettfo","html_url":"https://github.com/brettfo","followers_url":"https://api.github.com/users/brettfo/followers","following_url":"https://api.github.com/users/brettfo/following{/other_user}","gists_url":"https://api.github.com/users/brettfo/gists{/gist_id}","starred_url":"https://api.github.com/users/brettfo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettfo/subscriptions","organizations_url":"https://api.github.com/users/brettfo/orgs","repos_url":"https://api.github.com/users/brettfo/repos","events_url":"https://api.github.com/users/brettfo/events{/privacy}","received_events_url":"https://api.github.com/users/brettfo/received_events","type":"User","site_admin":false},"created_at":"2017-09-21T17:25:53Z","updated_at":"2017-09-21T17:25:53Z","author_association":"MEMBER","body":"@dotnet-bot test Windows_NT Release_ci_part2 please"}}
{"actor":{"display_login":"brettfo"}}