Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitefb0c3e

Browse files
committed
Make F# resources work more like C#
Given a resource in a folder named `AFolder/AResourceFile.txt` in a project witha root namespace of `fsharpresources`, then the following command line argshould be passed to the compiler```--resource:AFolder/AResourceFile.txt,fsharpresources.AFolder.AResourceFile.txt```whereas currently it just passes the name of the file. This also fixes passinga `LogicalName` to the resource.Fixesdotnet/fsharp#1050 &&dotnet/fsharp#922I looked at how Roslyn was doing this [here](https://github.com/dotnet/roslyn/blob/6847f1e5a909395aae9456e8f366cbf4deb86b69/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs#L739)es. Lines starting
1 parent7975efc commitefb0c3e

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

‎src/fsharp/FSharp.Build/CreateFSharpManifestResourceName.fs‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,15 @@ type CreateFSharpManifestResourceName public () =
2323
//
2424
// For resx resources, both the Visual FSharp and XBuild FSHarp toolchains do the right thing, i.e.
2525
// SubDir\abc.resx --> SubDir.abc.resources
26-
//
27-
// However for non-resx resources, for some reason Visual FSharp does _not_ add the directory name to the resource name.
28-
// It is very unclear where the directory name gets dropped in the Visual FSharp implementation
29-
// - is it in Microsoft.Common.targets, Microsoft.FSharp.Targets or how the base type CreateCSharpManifestResourceName
30-
// is created and used - who knows, the code is not easy to understand despite it doing something very simple. That's
31-
// the nature of MSBuild/XBuild....
32-
//
33-
// Anyway, dropping the directory name seems like a mistake. But we attempt to replicate the behaviour here
34-
// for consistency with Visual FSharp. This may not be the right place to do this and this many not be consistent
35-
// when cultures are used - that case has not been tested.
36-
37-
letrunningOnMono=
38-
try
39-
System.Type.GetType("Mono.Runtime")<>null
40-
with e->
41-
false
42-
letfileName=ifnot runningOnMono|| fileName.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)then fileNameelse Path.GetFileName(fileName)
43-
letlinkFileName=ifnot runningOnMono|| linkFileName.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)then linkFileNameelse Path.GetFileName(linkFileName)
4426

4527
letembeddedFileName=
4628
match linkFileNamewith
4729
|null-> fileName
4830
|_-> linkFileName
4931

5032
// since we do not support resources dependent on a form, we always pass null for a binary stream
51-
// rootNamespace is always empty - we do not support it
5233
letcSharpResult=
53-
base.CreateManifestName(fileName, linkFileName,"", dependentUponFileName,null)
34+
base.CreateManifestName(fileName, linkFileName,rootNamespace, dependentUponFileName,null)
5435
// Workaround that makes us keep .resources extension on both 3.5 and 3.5SP1
5536
// 3.5 stripped ".resources", 3.5 SP1 does not. We should do 3.5SP1 thing
5637
letextensionToWorkaround=".resources"

‎src/fsharp/FSharp.Build/Fsc.fs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ type FscCommandLineBuilder () =
6060
if s<> String.Emptythen
6161
args<- s:: args
6262

63-
memberx.AppendSwitchIfNotNull(switch:string,value:string)=
63+
memberx.AppendSwitchIfNotNull(switch:string,value:string,?metadataNames:string array)=
64+
letmetadataNames= defaultArg metadataNames[||]
6465
builder.AppendSwitchIfNotNull(switch, value)
6566
lettmp=new CommandLineBuilder()
6667
tmp.AppendSwitchUnquotedIfNotNull(switch, value)
68+
letprovidedMetaData=
69+
metadataNames
70+
|> Array.filter(String.IsNullOrWhiteSpace>>not)
71+
if providedMetaData.Length>0then
72+
tmp.AppendTextUnquoted","
73+
tmp.AppendTextUnquoted(providedMetaData|> String.concat",")
6774
lets= tmp.ToString()
6875
if s<> String.Emptythen
6976
args<- s:: args
@@ -242,7 +249,7 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
242249
// Resources
243250
if resources<>nullthen
244251
for itemin resourcesdo
245-
builder.AppendSwitchIfNotNull("--resource:", item.ItemSpec)
252+
builder.AppendSwitchIfNotNull("--resource:", item.ItemSpec,[|item.GetMetadata("LogicalName"); item.GetMetadata("Access")|])
246253
// VersionFile
247254
builder.AppendSwitchIfNotNull("--versionfile:", versionFile)
248255
// References

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp