Skip to content

Commit 6282a73

Browse files
committed
Support to enable <EmbedInteropTypes> for a nuget package
1 parent 1f5110d commit 6282a73

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎docs/content/references-files.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ DotNetZip framework: >= net45
7979
FSharp.Core redirects: on
8080
```
8181

82+
## Adding support for COM interop DLL
83+
Follows the same syntax as the previous one:
84+
`PkgName embed_interop_types: true`
85+
In case it is not enabled, the default behavior is to drop `<EmbedInteropTypes>` from the project file.
86+
8287
## Excluding libraries
8388

8489
This option allows you to exclude libraries from being referenced in project files:

‎src/Paket.Core/PaketConfigFiles/ProjectFile.fs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ module ProjectFile =
723723
AnalyzersNode : XmlElement
724724
}
725725

726-
let generateXml (model:InstallModel) (usedFrameworkLibs:HashSet<TargetProfile*string>) (aliases:Map<string,string>) (copyLocal:bool option) (specificVersion:bool option) (importTargets:bool) (referenceCondition:string option) (allTargetProfiles:Set<TargetProfile>) (project:ProjectFile) : XmlContext =
726+
let generateXml (model:InstallModel) (usedFrameworkLibs:HashSet<TargetProfile*string>) (aliases:Map<string,string>) (embedInteropTypes:bool option) (copyLocal:bool option) (specificVersion:bool option) (importTargets:bool) (referenceCondition:string option) (allTargetProfiles:Set<TargetProfile>) (project:ProjectFile) : XmlContext =
727727
let references =
728728
getCustomReferenceAndFrameworkNodes project
729729
|> List.map (fun node -> node.Attributes.["Include"].InnerText.Split(',').[0])
@@ -767,6 +767,10 @@ module ProjectFile =
767767
| None -> n
768768
| Some(bool) -> addChild (createNodeSet "SpecificVersion" specificVersionSettings project) n
769769
|> addChild (createNodeSet "Paket" "True" project)
770+
|> fun n ->
771+
match embedInteropTypes with
772+
| None -> n
773+
| _ -> addChild (createNodeSet "EmbedInteropTypes" "True" project) n
770774
|> fun n ->
771775
match aliases with
772776
| None -> n
@@ -1237,7 +1241,7 @@ module ProjectFile =
12371241
let importTargets = defaultArg installSettings.ImportTargets true
12381242

12391243
let allFrameworks = applyRestrictionsToTargets restrictionList KnownTargetProfiles.AllProfiles
1240-
generateXml projectModel usedFrameworkLibs installSettings.Aliases installSettings.CopyLocal installSettings.SpecificVersion importTargets installSettings.ReferenceCondition (set allFrameworks) project)
1244+
generateXml projectModel usedFrameworkLibs installSettings.Aliases installSettings.EmbedInteropTypes installSettings.CopyLocal installSettings.SpecificVersion importTargets installSettings.ReferenceCondition (set allFrameworks) project)
12411245

12421246
for ctx in contexts do
12431247
for chooseNode in ctx.ChooseNodes do
@@ -1726,7 +1730,7 @@ type ProjectFile with
17261730

17271731
member this.DeleteCustomModelNodes(model:InstallModel) = ProjectFile.deleteCustomModelNodes model this
17281732

1729-
member this.GenerateXml(model, usedFrameworkLibs:HashSet<TargetProfile*string>, aliases, copyLocal, specificVersion, importTargets, allTargetProfiles:#seq<TargetProfile>, referenceCondition) = ProjectFile.generateXml model usedFrameworkLibs aliases copyLocal specificVersion importTargets referenceCondition (set allTargetProfiles) this
1733+
member this.GenerateXml(model, usedFrameworkLibs:HashSet<TargetProfile*string>, aliases, embedInteropTypes, copyLocal, specificVersion, importTargets, allTargetProfiles:#seq<TargetProfile>, referenceCondition) = ProjectFile.generateXml model usedFrameworkLibs aliases embedInteropTypes copyLocal specificVersion importTargets referenceCondition (set allTargetProfiles) this
17301734

17311735
member this.RemovePaketNodes () = ProjectFile.removePaketNodes this
17321736

‎src/Paket.Core/PaketConfigFiles/ReferencesFile.fs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ type ReferencesFile =
128128
{ ReferencesFile.FromLines lines with FileName = fileName }
129129
with e -> raise (new Exception(sprintf "Could not parse reference file '%s': %s" fileName e.Message, e))
130130

131-
member this.AddNuGetReference(groupName, packageName : PackageName, copyLocal: bool, specificVersion: bool, importTargets: bool, frameworkRestrictions, includeVersionInPath, downloadLicense, omitContent : bool, createBindingRedirects, referenceCondition) =
131+
member this.AddNuGetReference(groupName, packageName : PackageName, embedInteropTypes: bool, copyLocal: bool, specificVersion: bool, importTargets: bool, frameworkRestrictions, includeVersionInPath, downloadLicense, omitContent : bool, createBindingRedirects, referenceCondition) =
132132
let package: PackageInstallSettings =
133133
{ Name = packageName
134134
Settings =
135-
{ CopyLocal = if not copyLocal then Some copyLocal else None
135+
{ EmbedInteropTypes = if embedInteropTypes then Some embedInteropTypes else None
136+
CopyLocal = if not copyLocal then Some copyLocal else None
136137
SpecificVersion = if not specificVersion then Some specificVersion else None
137138
CopyContentToOutputDirectory = None
138139
StorageConfig = None
@@ -172,7 +173,7 @@ type ReferencesFile =
172173
{ this with Groups = newGroups }
173174

174175
member this.AddNuGetReference(groupName, packageName : PackageName) =
175-
this.AddNuGetReference(groupName, packageName, true, true, true, ExplicitRestriction FrameworkRestriction.NoRestriction, false, false, false, None, null)
176+
this.AddNuGetReference(groupName, packageName, false, true, true, true, ExplicitRestriction FrameworkRestriction.NoRestriction, false, false, false, None, null)
176177

177178
member this.RemoveNuGetReference(groupName, packageName : PackageName) =
178179
let group = this.Groups.[groupName]

‎src/Paket.Core/Versioning/Requirements.fs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ type InstallSettings =
883883
LicenseDownload: bool option
884884
ReferenceCondition : string option
885885
CreateBindingRedirects : BindingRedirectsSettings option
886+
EmbedInteropTypes : bool option
886887
CopyLocal : bool option
887888
SpecificVersion : bool option
888889
StorageConfig : PackagesFolderGroupConfig option
@@ -892,7 +893,8 @@ type InstallSettings =
892893
GenerateLoadScripts : bool option }
893894

894895
static member Default =
895-
{ CopyLocal = None
896+
{ EmbedInteropTypes = None
897+
CopyLocal = None
896898
SpecificVersion = None
897899
StorageConfig = None
898900
ImportTargets = None
@@ -1046,6 +1048,10 @@ type InstallSettings =
10461048
| x -> failwithf "Unknown copy_content_to_output_dir settings: %A" x
10471049
Excludes = []
10481050
Aliases = Map.empty
1051+
EmbedInteropTypes =
1052+
match getPair "embed_interop_types" with
1053+
| Some "true" -> Some true
1054+
| _ -> None
10491055
CopyLocal =
10501056
match getPair "copy_local" with
10511057
| Some "false" -> Some false

0 commit comments

Comments
 (0)