Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/Accounts/Accounts/Accounts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PreLoadAssemblies Include="$(RepoSrc)lib\Newtonsoft.Json.10.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.Buffers.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.Net.Http.WinHttpHandler.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.Private.ServiceModel.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.Reflection.DispatchProxy.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.Security.AccessControl.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.Security.Permissions.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.Security.Principal.Windows.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\System.ServiceModel.Primitives.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\Microsoft.IdentityModel.Clients.ActiveDirectory\NetFx\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\Microsoft.IdentityModel.Clients.ActiveDirectory\NetFx\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\Azure.Core\PreloadAssemblies\*.dll" />
<NetCoreAssemblies Include="$(RepoSrc)lib\Azure.Core\NetCoreAssemblies\*.dll" />
<NetCoreAssemblies Include="$(RepoSrc)lib\Microsoft.IdentityModel.Clients.ActiveDirectory\NetCore\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" />
<NetCoreAssemblies Include="$(RepoSrc)lib\Microsoft.IdentityModel.Clients.ActiveDirectory\NetCore\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll" />
<PreLoadAssemblies Include="$(RepoSrc)lib\NetFxPreloadAssemblies\*.dll" />
<NetCoreAssemblies Include="$(RepoSrc)lib\NetCorePreloadAssemblies\*.dll" />
<StorageDependencies Include="$(RepoSrc)lib\WindowsAzure.Storage\9.3.0\Microsoft.WindowsAzure.Storage.dll" />
<StorageDependencies Include="$(RepoSrc)lib\WindowsAzure.Storage\9.3.0\Microsoft.WindowsAzure.Storage.DataMovement.dll" />
</ItemGroup>
Expand All @@ -38,10 +25,12 @@
<Copy SourceFiles="@(PreLoadAssemblies)" DestinationFolder="$(TargetDir)\PreloadAssemblies" />
<Copy SourceFiles="@(NetCoreAssemblies)" DestinationFolder="$(TargetDir)\NetCoreAssemblies" />
<Copy SourceFiles="@(StorageDependencies)" DestinationFolder="$(TargetDir)" />
<Copy SourceFiles="$(RepoSrc)lib\PreloadAssemblyInfo.json" DestinationFolder="$(TargetDir)" />
</Target>

<ItemGroup>
<None Update="StartupScripts\AzError.ps1" CopyToOutputDirectory="PreserveNewest" />
<None Update="StartupScripts\InitializeAssemblyResolver.ps1" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<None Update="PostImportScripts\LoadAuthenticators.ps1" CopyToOutputDirectory="PreserveNewest" />
Expand Down
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Update preloaded assemblies [#12024,#11976]
* Updated Azure.Core assembly
* Fixed an issue that may cause `Connect-AzAccount` to fail in multi-threaded execution [#11201]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
try {
[Microsoft.Azure.PowerShell.Authenticators.DesktopAuthenticatorBuilder]::Apply([Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance)
} catch {}

try {
[Microsoft.Azure.Commands.Profile.Utilities.CustomAssemblyResolver]::Initialize()
} catch {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if ($PSEdition -eq 'Desktop') {
try {
[Microsoft.Azure.Commands.Profile.Utilities.CustomAssemblyResolver]::Initialize()
} catch {}
}
30 changes: 24 additions & 6 deletions src/Accounts/Accounts/Utilities/CustomAssemblyResolver.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Profile.Utilities
{
public static class CustomAssemblyResolver
{
private static IDictionary<string, Version> NetFxPreloadAssemblies =
new Dictionary<string, Version>(StringComparer.InvariantCultureIgnoreCase);

private static string PreloadAssemblyFolder { get; set; }

public static void Initialize()
{
var accountFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
PreloadAssemblyFolder = Path.Combine(accountFolder, "PreloadAssemblies");
var assemblyInfo = File.ReadAllText(Path.Combine(accountFolder, "PreloadAssemblyInfo.json"));

var root = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(assemblyInfo);
var netfx = root["netfx"];
foreach(var info in netfx)
{
NetFxPreloadAssemblies[info.Key] = new Version(info.Value);
}

AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}

Expand All @@ -19,13 +37,13 @@ public static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEvent
try
{
AssemblyName name = new AssemblyName(args.Name);
if(string.Equals(name.Name, "Azure.Core", StringComparison.OrdinalIgnoreCase)
&& name.Version?.Major == 1 && (name.Version?.Minor == 2 && name.Version?.Build <= 1 ||
name.Version?.Minor == 1))
if (NetFxPreloadAssemblies.TryGetValue(args.Name, out Version version))
{
string accountFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string azureCorePath = Path.Combine(accountFolder, @"PreloadAssemblies\Azure.Core.dll");
return Assembly.LoadFrom(azureCorePath);
if (version >= name.Version && version.Major == name.Version.Major)
{
string requiredAssembly = Path.Combine(PreloadAssemblyFolder, $"{args.Name}.dll");
return Assembly.LoadFrom(requiredAssembly);
}
}
}
catch
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions src/lib/PreloadAssemblyInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"netfx": {
"Azure.Core": "1.2.1.0",
"Microsoft.Bcl.AsyncInterfaces": "1.0.0.0",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.19.2.6005",
"Microsoft.IdentityModel.Clients.ActiveDirectory.Platform": "3.19.2.6005",
"Newtonsoft.Json": "10.0.0.0",
"System.Buffers": "4.0.2.0",
"System.Diagnostics.DiagnosticSource": "4.0.4.0",
"System.Memory": "4.0.1.1",
"System.Net.Http.WinHttpHandler": "4.0.2.0",
"System.Numerics.Vectors": "4.1.3.0",
"System.Private.ServiceModel": "4.1.2.1",
"System.Reflection.DispatchProxy": "4.0.3.0",
"System.Runtime.CompilerServices.Unsafe": "4.0.5.0",
"System.Security.AccessControl": "4.1.1.0",
"System.Security.Permissions": "4.0.1.0",
"System.Security.Principal.Windows": "4.1.1.0",
"System.ServiceModel.Primitives": "4.2.0.0",
"System.Text.Encodings.Web": "4.0.4.0",
"System.Text.Json": "4.0.0.0",
"System.Threading.Tasks.Extensions": "4.2.0.0",
"System.Xml.ReaderWriter": "4.1.0.0"
},
"netcore": {
"Azure.Core": "1.2.1.0",
"Microsoft.Bcl.AsyncInterfaces": "1.0.0.0",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.19.2.6005",
"Microsoft.IdentityModel.Clients.ActiveDirectory.Platform": "3.19.2.6005",
"System.Numerics.Vectors": "4.1.4.0",
"System.Runtime.CompilerServices.Unsafe": "4.0.6.0",
"System.Text.Encodings.Web": "4.0.5.0",
"System.Text.Json": "4.0.0.0",
"System.Threading.Tasks.Extensions": "4.3.1.0"
}
}
Binary file removed src/lib/System.Security.AccessControl.dll
Binary file not shown.
Binary file removed src/lib/System.Security.Permissions.dll
Binary file not shown.
Binary file removed src/lib/System.Security.Principal.Windows.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lib/test.net472.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<codeBase version="9.0.0.0"
href="../../../../../lib/Newtonsoft.Json.9.dll"/>
<codeBase version="10.0.0.0"
href="../../../../../lib/Newtonsoft.Json.10.dll"/>
href="../../../../../libNetFxPreloadAssemblies/Newtonsoft.Json.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down