Hi,@fatih uyanık. Welcome to Microsoft Q&A.
I take CommunityToolkit.Mvvm
as an example. I downloaded CommunityToolkit.Mvvm
through NuGet
and set its output location to the Lib
folder when the project is generated.
First, move the CommunityToolkit.Mvvm.dll
location to the Lib
file through the Post-build event
:
WPF Application
Right click on the project-> Properties ->Build->Events->Post-build event->Enter the following code
mkdir $(OutputPath)\Lib
move $(OutputPath)\CommunityToolkit.Mvvm.dll $(OutputPath)\Lib\CommunityToolkit.Mvvm.dll
WPF App(.NET Framework)
Right click on the project->Properties->Build-Events->Post-build event command line->Enter the following code
mkdir Lib
move CommunityToolkit.Mvvm.dll Lib\CommunityToolkit.Mvvm.dll
Then reload the assembly:
WPF Application
Double-click the project and add <RuntimeHostConfigurationOption Include="SubdirectoriesToProbe" Value="Lib" />
in ItemGroup
<ItemGroup>
<RuntimeHostConfigurationOption Include="SubdirectoriesToProbe" Value="Lib" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
</ItemGroup>
Add the following code in App.xaml.cs
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
//Load Assembly Event
AssemblyLoadContext.Default.Resolving += ResolveAssembly;
base.OnStartup(e);
}
// Load the specified location assembly
private static Assembly ResolveAssembly(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName)
{
var probeSetting = AppContext.GetData("SubdirectoriesToProbe") as string;
if (string.IsNullOrEmpty(probeSetting))
{
return null;
}
foreach (var subDirectory in probeSetting.Split(';'))
{
var pathMaybe = Path.Combine(AppContext.BaseDirectory, subDirectory, $"{assemblyName.Name}.dll");
if (File.Exists(pathMaybe))
{
return assemblyLoadContext.LoadFromAssemblyPath(pathMaybe);
}
}
return null;
}
}
WPF App(.NET Framework)
Add the following code to <configuration>
in App.config
.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
…
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Lib;"/>
</assemblyBinding>
</runtime>
</configuration>
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.