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

Commit91ca7eb

Browse files
authored
Merge pull requestfsharp#761 from nosami/fsharp-resources
Make F# resources work more like C#
2 parentsd1329ac +c552a5a commit91ca7eb

File tree

5 files changed

+44
-23
lines changed

5 files changed

+44
-23
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ open Microsoft.Build.Utilities
99

1010
typeCreateFSharpManifestResourceNamepublic()=
1111
inherit CreateCSharpManifestResourceName()
12-
12+
13+
// When set to true, generate resource names in the same way as C# with root namespace and folder names
14+
member valUseStandardResourceNames=falsewith get, set
15+
1316
overridethis.CreateManifestName
1417
((fileName:string),
1518
(linkFileName:string),
@@ -23,34 +26,29 @@ type CreateFSharpManifestResourceName public () =
2326
//
2427
// For resx resources, both the Visual FSharp and XBuild FSHarp toolchains do the right thing, i.e.
2528
// 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.
3629

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)
30+
letfileName,linkFileName,rootNamespace=
31+
match this.UseStandardResourceNameswith
32+
|true->
33+
fileName, linkFileName, rootNamespace
34+
|false->
35+
letrunningOnMono=
36+
try
37+
System.Type.GetType("Mono.Runtime")<>null
38+
with e->
39+
false
40+
letfileName=ifnot runningOnMono|| fileName.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)then fileNameelse Path.GetFileName(fileName)
41+
letlinkFileName=ifnot runningOnMono|| linkFileName.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)then linkFileNameelse Path.GetFileName(linkFileName)
42+
fileName, linkFileName,""
4443

4544
letembeddedFileName=
4645
match linkFileNamewith
4746
|null-> fileName
4847
|_-> linkFileName
4948

5049
// 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
5250
letcSharpResult=
53-
base.CreateManifestName(fileName, linkFileName,"", dependentUponFileName,null)
51+
base.CreateManifestName(fileName, linkFileName,rootNamespace, dependentUponFileName,null)
5452
// Workaround that makes us keep .resources extension on both 3.5 and 3.5SP1
5553
// 3.5 stripped ".resources", 3.5 SP1 does not. We should do 3.5SP1 thing
5654
letextensionToWorkaround=".resources"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ namespace Microsoft.FSharp.Build
66
typeCreateFSharpManifestResourceName=
77
inherit Microsoft.Build.Tasks.CreateCSharpManifestResourceName
88
publicnew: unit-> CreateFSharpManifestResourceName
9+
memberUseStandardResourceNames:bool with get,set

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

Lines changed: 17 additions & 3 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
@@ -160,6 +167,7 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
160167
| Some s-> s
161168
| None->""
162169
let mutabletreatWarningsAsErrors:bool=false
170+
let mutableuseStandardResourceNames:bool=false
163171
let mutablewarningsAsErrors:string=null
164172
let mutableversionFile:string=null
165173
let mutablewarningLevel:string=null
@@ -242,7 +250,10 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
242250
// Resources
243251
if resources<>nullthen
244252
for itemin resourcesdo
245-
builder.AppendSwitchIfNotNull("--resource:", item.ItemSpec)
253+
match useStandardResourceNameswith
254+
|true-> builder.AppendSwitchIfNotNull("--resource:", item.ItemSpec,[|item.GetMetadata("LogicalName"); item.GetMetadata("Access")|])
255+
|false-> builder.AppendSwitchIfNotNull("--resource:", item.ItemSpec)
256+
246257
// VersionFile
247258
builder.AppendSwitchIfNotNull("--versionfile:", versionFile)
248259
// References
@@ -450,7 +461,10 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
450461
memberfsc.TargetType
451462
with get()= targetType
452463
andset(s)= targetType<- s
453-
464+
// When set to true, generate resource names in the same way as C# with root namespace and folder names
465+
memberfsc.UseStandardResourceNames
466+
with get()= useStandardResourceNames
467+
andset(s)= useStandardResourceNames<- s
454468
// --version-file <string>:
455469
memberfsc.VersionFile
456470
with get()= versionFile

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Fsc = class
4646
member TargetType: string with get,set
4747
member ToolPath: string with get,set
4848
member TreatWarningsAsErrors: bool with get,set
49+
member UseStandardResourceNames: bool with get,set
4950
member Utf8Output: bool with get,set
5051
member VisualStudioStyleErrors: bool with get,set
5152
member LCID: string with get,set

‎src/fsharp/FSharp.Build/Microsoft.FSharp.Targets‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,28 @@ this file.
8989

9090
<CreateFSharpManifestResourceName
9191
Condition="'@(ResxWithNoCulture)' != '' AND '$(UsingXBuild)' == 'true'"
92+
UseStandardResourceNames="$(UseStandardResourceNames)"
9293
ResourceFiles="@(ResxWithNoCulture)"RootNamespace="$(RootNamespace)">
9394
<Output TaskParameter ="ManifestResourceNames" ItemName ="ManifestResourceWithNoCultureName" />
9495
</CreateFSharpManifestResourceName>
9596

9697
<CreateFSharpManifestResourceName
9798
Condition="'@(NonResxWithNoCulture)' != '' AND '$(UsingXBuild)' == 'true'"
99+
UseStandardResourceNames="$(UseStandardResourceNames)"
98100
ResourceFiles="@(NonResxWithNoCulture)"RootNamespace="$(RootNamespace)">
99101
<Output TaskParameter ="ManifestResourceNames" ItemName ="ManifestNonResxWithNoCulture" />
100102
</CreateFSharpManifestResourceName>
101103

102104
<CreateFSharpManifestResourceName
103105
Condition="'@(ResxWithCulture)' != '' AND '$(UsingXBuild)' == 'true'"
106+
UseStandardResourceNames="$(UseStandardResourceNames)"
104107
ResourceFiles="@(ResxWithCulture)"RootNamespace="$(RootNamespace)">
105108
<Output TaskParameter ="ManifestResourceNames" ItemName ="ManifestResourceWithCultureName" />
106109
</CreateFSharpManifestResourceName>
107110

108111
<CreateFSharpManifestResourceName
109112
Condition="'@(NonResxWithCulture)' != '' AND '$(UsingXBuild)' == 'true'"
113+
UseStandardResourceNames="$(UseStandardResourceNames)"
110114
ResourceFiles="@(NonResxWithCulture)"RootNamespace="$(RootNamespace)">
111115
<Output TaskParameter ="ManifestResourceNames" ItemName ="ManifestNonResxWithCulture" />
112116
</CreateFSharpManifestResourceName>
@@ -123,6 +127,7 @@ this file.
123127
<CreateFSharpManifestResourceName
124128
ResourceFiles="@(EmbeddedResource)"
125129
RootNamespace="$(RootNamespace)"
130+
UseStandardResourceNames="$(UseStandardResourceNames)"
126131
Condition="'%(EmbeddedResource.ManifestResourceName)' == '' and ('%(EmbeddedResource.WithCulture)' == 'false' or '%(EmbeddedResource.Type)' == 'Resx') AND '$(UsingXBuild)' == 'false'">
127132

128133
<OutputTaskParameter="ResourceFilesWithManifestResourceNames"ItemName="_Temporary" />
@@ -133,6 +138,7 @@ this file.
133138
<CreateFSharpManifestResourceName
134139
ResourceFiles="@(EmbeddedResource)"
135140
RootNamespace="$(RootNamespace)"
141+
UseStandardResourceNames="$(UseStandardResourceNames)"
136142
PrependCultureAsDirectory="false"
137143
Condition="'%(EmbeddedResource.ManifestResourceName)' == '' and '%(EmbeddedResource.WithCulture)' == 'true' and '%(EmbeddedResource.Type)' == 'Non-Resx' AND '$(UsingXBuild)' == 'false'">
138144

@@ -253,6 +259,7 @@ this file.
253259
ToolExe="$(FscToolExe)"
254260
ToolPath="$(FscToolPath)"
255261
TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
262+
UseStandardResourceNames="$(UseStandardResourceNames)"
256263
Utf8Output="$(Utf8Output)"
257264
VersionFile="$(VersionFile)"
258265
VisualStudioStyleErrors="$(VisualStudioStyleErrors)"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp