Skip to content

Commit 445d66d

Browse files
committed
Updating for platform-specific assembly loading
1 parent 5369c74 commit 445d66d

File tree

5 files changed

+39
-46
lines changed

5 files changed

+39
-46
lines changed

src/StorageSync/StorageSync/Az.StorageSync.psd1

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,53 +55,8 @@ RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '1.3.0'; })
5555

5656
# Assemblies that must be loaded prior to importing this module
5757
RequiredAssemblies = '.\Microsoft.Azure.Management.StorageSync.dll',
58-
'.\Microsoft.Win32.Registry.dll',
5958
'.\System.Management.dll',
60-
'.\System.CodeDom.dll',
61-
'.\Microsoft.ApplicationInsights.dll',
62-
'.\Microsoft.Azure.PowerShell.Clients.Aks.dll',
63-
'.\Microsoft.Azure.PowerShell.Clients.Compute.dll',
64-
'.\Microsoft.Azure.PowerShell.Clients.KeyVault.dll',
65-
'.\Microsoft.Azure.PowerShell.Clients.Network.dll',
66-
'.\Microsoft.Azure.PowerShell.Clients.Storage.Management.dll',
67-
'.\Microsoft.Azure.PowerShell.Clients.Websites.dll',
68-
'.\Microsoft.Azure.PowerShell.Storage.dll',
69-
'.\Microsoft.Azure.PowerShell.Strategies.dll',
70-
'.\Microsoft.CSharp.dll',
71-
'.\Newtonsoft.Json.dll',
72-
'.\System.Buffers.dll',
73-
'.\System.Collections.Concurrent.dll',
74-
'.\System.Collections.Immutable.dll',
75-
'.\System.Collections.Specialized.dll',
76-
'.\System.ComponentModel.dll',
77-
'.\System.ComponentModel.Primitives.dll',
78-
'.\System.ComponentModel.TypeConverter.dll',
79-
'.\System.Diagnostics.DiagnosticSource.dll',
80-
'.\System.Diagnostics.StackTrace.dll',
81-
'.\System.Dynamic.Runtime.dll',
82-
'.\System.IO.FileSystem.Primitives.dll',
83-
'.\System.Linq.dll',
84-
'.\System.Linq.Expressions.dll',
85-
'.\System.Management.Automation.dll',
86-
'.\System.Numerics.Vectors.dll',
87-
'.\System.ObjectModel.dll',
88-
'.\System.Reflection.Emit.dll',
89-
'.\System.Reflection.Emit.ILGeneration.dll',
90-
'.\System.Reflection.Emit.Lightweight.dll',
91-
'.\System.Reflection.Metadata.dll',
92-
'.\System.Reflection.TypeExtensions.dll',
93-
'.\System.Runtime.CompilerServices.Unsafe.dll',
94-
'.\System.Runtime.Numerics.dll',
95-
'.\System.Runtime.Serialization.Formatters.dll',
96-
'.\System.Runtime.Serialization.Primitives.dll',
97-
'.\System.Security.Cryptography.OpenSsl.dll',
98-
'.\System.Security.Cryptography.Primitives.dll',
99-
'.\System.Security.Principal.Windows.dll',
100-
'.\System.Text.RegularExpressions.dll',
101-
'.\System.Threading.Tasks.Extensions.dll',
102-
'.\System.Xml.ReaderWriter.dll',
103-
'.\System.Xml.XmlDocument.dll',
104-
'.\System.Xml.XmlSerializer.dll'
59+
'.\System.CodeDom.dll'
10560

10661
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
10762
# ScriptsToProcess = @()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$platformDirectory = Join-Path $PSScriptRoot "PlatformAssemblies"
2+
if ($PSEdition -eq 'Desktop' -or $IsWindows) {
3+
$platformDirectory = Join-Path $platformDirectory "win"
4+
}
5+
elseif ($IsLinux -or $IsMacOs) {
6+
$platformDirectory = Join-Path $platformDirectory "unix"
7+
}
8+
9+
try {
10+
$loadedAssemblies = ([System.AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object {New-Object -TypeName System.Reflection.AssemblyName -ArgumentList $_.FullName} )
11+
if (Test-Path $platformDirectory -ErrorAction Ignore) {
12+
Get-ChildItem -Path $platformDirectory -Filter *.dll -ErrorAction Stop | ForEach-Object {
13+
$assemblyName = ([System.Reflection.AssemblyName]::GetAssemblyName($_.FullName))
14+
$matches = ($loadedAssemblies | Where-Object {$_.Name -eq $assemblyName.Name})
15+
if (-not $matches)
16+
{
17+
Add-Type -Path $_.FullName -ErrorAction Ignore | Out-Null
18+
}
19+
}
20+
}
21+
}
22+
catch {}

src/StorageSync/StorageSync/StorageSync.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
1717
<PackageReference Include="System.Management" Version="4.5.0" />
1818
</ItemGroup>
19+
20+
<ItemGroup>
21+
<WinPlatformAssemblies Include="$(RepoSrc)lib\Microsoft.Win32.Registry\win\*.dll" />
22+
<UnixPlatformAssemblies Include="$(RepoSrc)lib\Microsoft.Win32.Registry\unix\*.dll" />
23+
</ItemGroup>
1924

2025
<ItemGroup>
2126
<EmbeddedResource Include="Config.json" />
@@ -36,4 +41,15 @@
3641
</EmbeddedResource>
3742
</ItemGroup>
3843

44+
<Target Name="CopyFiles" AfterTargets="Build">
45+
<Copy SourceFiles="@(WinPlatformAssemblies)" DestinationFolder="$(TargetDir)\PlatformAssemblies\win" />
46+
<Copy SourceFiles="@(UnixPlatformAssemblies)" DestinationFolder="$(TargetDir)\PlatformAssemblies\unix" />
47+
</Target>
48+
49+
<ItemGroup>
50+
<None Update="StartupScripts\LoadPlatformAssemblies.ps1" CopyToOutputDirectory="PreserveNewest" />
51+
</ItemGroup>
52+
53+
54+
3955
</Project>
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)