Skip to content

Commit

Permalink
Sample: Assembly resolution (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfevia authored Jul 11, 2024
1 parent d1fed14 commit c88dee2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Azure.Core" Version="1.40.0" />
<PackageVersion Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK" Version="1.4.233.23144-rc" />
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.26100.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
10 changes: 10 additions & 0 deletions PowerAutomate.Desktop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GettingStarted", "GettingSt
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modules.GettingStarted.Actions", "samples\Modules.GettingStarted.Actions\Modules.GettingStarted.Actions.csproj", "{1D4838E3-22A7-4D65-91CF-2395778EE92F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AssemblyResolution", "AssemblyResolution", "{8EC670BB-BC22-44B4-8228-8F053188C908}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modules.AssemblyResolution.Actions", "samples\Modules.AssemblyResolution.Actions\Modules.AssemblyResolution.Actions.csproj", "{146D4CFB-A54A-4E9F-8473-FC0D73F7BEFD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -87,6 +91,10 @@ Global
{1D4838E3-22A7-4D65-91CF-2395778EE92F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D4838E3-22A7-4D65-91CF-2395778EE92F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D4838E3-22A7-4D65-91CF-2395778EE92F}.Release|Any CPU.Build.0 = Release|Any CPU
{146D4CFB-A54A-4E9F-8473-FC0D73F7BEFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{146D4CFB-A54A-4E9F-8473-FC0D73F7BEFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{146D4CFB-A54A-4E9F-8473-FC0D73F7BEFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{146D4CFB-A54A-4E9F-8473-FC0D73F7BEFD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -108,6 +116,8 @@ Global
{EE7E70E2-7838-4B4E-BCC1-C74051ACBBA5} = {3B78C634-DFD6-43DA-A30E-33AC42224BD4}
{A5E3C936-7C1F-4719-9EAA-37F4AE439EF7} = {64A2FE14-920C-4A2F-8F4A-28B77CC84BA4}
{1D4838E3-22A7-4D65-91CF-2395778EE92F} = {A5E3C936-7C1F-4719-9EAA-37F4AE439EF7}
{8EC670BB-BC22-44B4-8228-8F053188C908} = {64A2FE14-920C-4A2F-8F4A-28B77CC84BA4}
{146D4CFB-A54A-4E9F-8473-FC0D73F7BEFD} = {8EC670BB-BC22-44B4-8228-8F053188C908}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Modules.Actions.Shared\Modules.Actions.Shared.projitems*{7e19e2f1-6de7-4a0e-aed8-7cea38b166af}*SharedItemsImports = 13
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// --------------------------------------------------------------
// Copyright (c) Jesus Fernandez. All Rights Reserved.
// --------------------------------------------------------------

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Azure.Core;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes;

namespace PowerAutomate.Desktop.Modules.AssemblyResolution.Actions;

[Action]
public class AssemblyResolutionAction : ActionBase
{
public override void Execute(ActionContext context)
{
Debugger.Launch();

try
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

var accessToken = new AccessToken();
Debug.WriteLine($"Access token expires on {accessToken.ExpiresOn}");
}
finally
{
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
}
}

private static Assembly? CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
var assemblyName = new AssemblyName(args.Name);
var directoryName = AppDomain.CurrentDomain.BaseDirectory;
return !string.IsNullOrEmpty(directoryName) ? Assembly.LoadFile(Path.Combine(directoryName, $"{assemblyName.Name}.dll")) : null;
}
catch (Exception)
{
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>GettingStarted</AssemblyTitle>
<TargetFramework>net472</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<PackCustomModule Condition=" '$(Configuration)' == 'Debug' ">true</PackCustomModule>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK" />
</ItemGroup>

</Project>

0 comments on commit c88dee2

Please sign in to comment.